aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/analysis
diff options
context:
space:
mode:
authorFederico Bond <federicobond@gmail.com>2017-06-22 22:14:14 +0800
committerFederico Bond <federicobond@gmail.com>2017-06-24 10:21:19 +0800
commit7a3ea61ffd226cc09ef419c47c0506699aa69b50 (patch)
treeeb5aec7a7f92c2b1811fa9d552a6940fc2b12315 /libsolidity/analysis
parent26ea9ce07cf85849cd881465a4322f14bff87eb8 (diff)
downloaddexon-solidity-7a3ea61ffd226cc09ef419c47c0506699aa69b50.tar.gz
dexon-solidity-7a3ea61ffd226cc09ef419c47c0506699aa69b50.tar.zst
dexon-solidity-7a3ea61ffd226cc09ef419c47c0506699aa69b50.zip
Warn if decimal literals are used in a bytesXX context
Fixes #2349
Diffstat (limited to 'libsolidity/analysis')
-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 2a8d1ff6..cb9435e8 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>
@@ -1793,7 +1794,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)