Merge pull request #4388 from ethereum/noPackedLiterals

Disallow packed encoding of literals.
This commit is contained in:
chriseth
2018-07-11 14:28:20 +02:00
committed by GitHub
6 changed files with 20 additions and 32 deletions
+7 -17
View File
@@ -1651,8 +1651,6 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
else
_functionCall.annotation().type = make_shared<TupleType>(returnTypes);
bool const v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
if (auto functionName = dynamic_cast<Identifier const*>(&_functionCall.expression()))
{
if (functionName->name() == "sha3" && functionType->kind() == FunctionType::Kind::SHA3)
@@ -1672,23 +1670,15 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
auto const& argType = type(*arguments[i]);
if (auto literal = dynamic_cast<RationalNumberType const*>(argType.get()))
{
/* If no mobile type is available an error will be raised elsewhere. */
if (literal->mobileType())
m_errorReporter.typeError(
arguments[i]->location(),
"Cannot perform packed encoding for a literal. Please convert it to an explicit type first."
);
else
{
if (v050)
m_errorReporter.typeError(
arguments[i]->location(),
"Cannot perform packed encoding for a literal. Please convert it to an explicit type first."
);
else
m_errorReporter.warning(
arguments[i]->location(),
"The type of \"" +
argType->toString() +
"\" was inferred as " +
literal->mobileType()->toString() +
". This is probably not desired. Use an explicit type to silence this warning."
);
/* If no mobile type is available an error will be raised elsewhere. */
solAssert(m_errorReporter.hasErrors(), "");
}
}
}
+6
View File
@@ -92,6 +92,12 @@ public:
void clear();
/// @returns true iff there is any error (ignores warnings).
bool hasErrors() const
{
return m_errorCount > 0;
}
private:
void error(Error::Type _type,
SourceLocation const& _location,