From 7a3ea61ffd226cc09ef419c47c0506699aa69b50 Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Thu, 22 Jun 2017 11:14:14 -0300 Subject: Warn if decimal literals are used in a bytesXX context Fixes #2349 --- libsolidity/analysis/TypeChecker.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'libsolidity') 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 #include +#include #include #include #include @@ -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(&_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) -- cgit v1.2.3