Warn if decimal literals are used in a bytesXX context

Fixes #2349
This commit is contained in:
Federico Bond
2017-06-23 23:21:19 -03:00
parent 26ea9ce07c
commit 7a3ea61ffd
2 changed files with 50 additions and 3 deletions
+18 -1
View File
@@ -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)