aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-06-26 15:13:41 +0800
committerGitHub <noreply@github.com>2017-06-26 15:13:41 +0800
commitf879489291b78a7872c13d3235e1d345883880b4 (patch)
tree42b0df78242412d4b620579f5eb2b4db4b6e2d85 /libsolidity
parent29b8cdb594044525b398994fe9855fbbdb76981b (diff)
parent7a3ea61ffd226cc09ef419c47c0506699aa69b50 (diff)
downloaddexon-solidity-f879489291b78a7872c13d3235e1d345883880b4.tar
dexon-solidity-f879489291b78a7872c13d3235e1d345883880b4.tar.gz
dexon-solidity-f879489291b78a7872c13d3235e1d345883880b4.tar.bz2
dexon-solidity-f879489291b78a7872c13d3235e1d345883880b4.tar.lz
dexon-solidity-f879489291b78a7872c13d3235e1d345883880b4.tar.xz
dexon-solidity-f879489291b78a7872c13d3235e1d345883880b4.tar.zst
dexon-solidity-f879489291b78a7872c13d3235e1d345883880b4.zip
Merge pull request #2449 from federicobond/warn-bytesxx-decimal
Warn if decimal literals are used in a bytesXX context
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 40853608..615bc402 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -22,6 +22,7 @@
#include <libsolidity/analysis/TypeChecker.h>
#include <memory>
+#include <boost/algorithm/string/predicate.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <libsolidity/ast/AST.h>
#include <libsolidity/inlineasm/AsmAnalysis.h>
@@ -1800,7 +1801,23 @@ void TypeChecker::expectType(Expression const& _expression, Type const& _expecte
_expectedType.toString() +
"."
);
- }
+ }
+
+ if (
+ type(_expression)->category() == Type::Category::RationalNumber &&
+ _expectedType.category() == Type::Category::FixedBytes
+ )
+ {
+ auto literal = dynamic_cast<Literal const*>(&_expression);
+
+ if (literal && !boost::starts_with(literal->value(), "0x"))
+ m_errorReporter.warning(
+ _expression.location(),
+ "Decimal literal assigned to bytesXX variable will be left-aligned. "
+ "Use an explicit conversion to silence this warning."
+ );
+ }
+
}
void TypeChecker::requireLValue(Expression const& _expression)