More precise error message if using non-variables with _slot/_offset

This commit is contained in:
Alex Beregszaszi 2018-08-07 13:17:56 +01:00
parent eb7b3862ac
commit 05cc7e79e1
3 changed files with 8 additions and 4 deletions

View File

@ -262,8 +262,6 @@ bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly)
return size_t(-1); return size_t(-1);
} }
declarations = m_resolver.nameFromCurrentScope(realName); declarations = m_resolver.nameFromCurrentScope(realName);
if (!dynamic_cast<VariableDeclaration const*>(declarations.front()))
return size_t(-1);
} }
if (declarations.size() != 1) if (declarations.size() != 1)
return size_t(-1); return size_t(-1);

View File

@ -867,6 +867,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
return size_t(-1); return size_t(-1);
Declaration const* declaration = ref->second.declaration; Declaration const* declaration = ref->second.declaration;
solAssert(!!declaration, ""); solAssert(!!declaration, "");
bool requiresStorage = ref->second.isSlot || ref->second.isOffset;
if (auto var = dynamic_cast<VariableDeclaration const*>(declaration)) if (auto var = dynamic_cast<VariableDeclaration const*>(declaration))
{ {
if (var->isConstant()) if (var->isConstant())
@ -874,7 +875,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
m_errorReporter.typeError(_identifier.location, "Constant variables not supported by inline assembly."); m_errorReporter.typeError(_identifier.location, "Constant variables not supported by inline assembly.");
return size_t(-1); return size_t(-1);
} }
else if (ref->second.isSlot || ref->second.isOffset) else if (requiresStorage)
{ {
if (!var->isStateVariable() && !var->type()->dataStoredIn(DataLocation::Storage)) if (!var->isStateVariable() && !var->type()->dataStoredIn(DataLocation::Storage))
{ {
@ -906,6 +907,11 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
return size_t(-1); return size_t(-1);
} }
} }
else if (requiresStorage)
{
m_errorReporter.typeError(_identifier.location, "The suffixes _offset and _slot can only be used on storage variables.");
return size_t(-1);
}
else if (_context == julia::IdentifierContext::LValue) else if (_context == julia::IdentifierContext::LValue)
{ {
m_errorReporter.typeError(_identifier.location, "Only local variables can be assigned to in inline assembly."); m_errorReporter.typeError(_identifier.location, "Only local variables can be assigned to in inline assembly.");

View File

@ -6,4 +6,4 @@ contract C {
} }
} }
// ---- // ----
// DeclarationError: (84-90): Identifier not found. // TypeError: (84-90): The suffixes _offset and _slot can only be used on storage variables.