Fix storage access tests.

This commit is contained in:
chriseth 2017-04-25 13:15:42 +02:00
parent e841b23bfd
commit 1d712c7d64
3 changed files with 26 additions and 20 deletions

View File

@ -655,6 +655,11 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
return size_t(-1);
}
}
else if (var->isConstant())
{
typeError(_identifier.location, "Constant variables not supported by inline assembly.");
return size_t(-1);
}
else if (!var->isLocalVariable())
{
typeError(_identifier.location, "Only local variables are supported. To access storage variables, use the _slot and _offset suffixes.");
@ -670,11 +675,6 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
typeError(_identifier.location, "Only types that use one stack slot are supported.");
return size_t(-1);
}
else if (var->isConstant())
{
typeError(_identifier.location, "Constant variables not supported by inline assembly.");
return size_t(-1);
}
}
else if (_context == assembly::IdentifierContext::LValue)
{

View File

@ -79,6 +79,7 @@ bool AsmAnalyzer::operator()(assembly::Literal const& _literal)
bool AsmAnalyzer::operator()(assembly::Identifier const& _identifier)
{
size_t numErrorsBefore = m_errors.size();
bool success = true;
if (m_currentScope->lookup(_identifier.name, Scope::Visitor(
[&](Scope::Variable const& _var)
@ -117,11 +118,13 @@ bool AsmAnalyzer::operator()(assembly::Identifier const& _identifier)
stackSize = m_resolver(_identifier, IdentifierContext::RValue);
if (stackSize == size_t(-1))
{
m_errors.push_back(make_shared<Error>(
Error::Type::DeclarationError,
"Identifier not found.",
_identifier.location
));
// Only add an error message if the callback did not do it.
if (numErrorsBefore == m_errors.size())
m_errors.push_back(make_shared<Error>(
Error::Type::DeclarationError,
"Identifier not found.",
_identifier.location
));
success = false;
}
m_stackHeight += stackSize == size_t(-1) ? 1 : stackSize;
@ -292,6 +295,7 @@ bool AsmAnalyzer::operator()(Block const& _block)
bool AsmAnalyzer::checkAssignment(assembly::Identifier const& _variable, size_t _valueSize)
{
bool success = true;
size_t numErrorsBefore = m_errors.size();
size_t variableSize(-1);
if (Scope::Identifier const* var = m_currentScope->lookup(_variable.name))
{
@ -320,11 +324,13 @@ bool AsmAnalyzer::checkAssignment(assembly::Identifier const& _variable, size_t
variableSize = m_resolver(_variable, IdentifierContext::LValue);
if (variableSize == size_t(-1))
{
m_errors.push_back(make_shared<Error>(
Error::Type::DeclarationError,
"Variable not found or variable not lvalue.",
_variable.location
));
// Only add message if the callback did not.
if (numErrorsBefore == m_errors.size())
m_errors.push_back(make_shared<Error>(
Error::Type::DeclarationError,
"Variable not found or variable not lvalue.",
_variable.location
));
success = false;
}
if (_valueSize == size_t(-1))

View File

@ -5024,7 +5024,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_unbalanced_two_stack_load)
}
}
)";
CHECK_ERROR(text, DeclarationError, "Unbalanced stack at the end of a block: 1 surplus item(s).");
CHECK_ERROR(text, TypeError, "Only local variables are supported. To access storage variables,");
}
BOOST_AUTO_TEST_CASE(inline_assembly_in_modifier)
@ -5057,7 +5057,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_storage)
}
}
)";
CHECK_ERROR(text, DeclarationError, "Variable not found or variable not lvalue.");
CHECK_ERROR(text, TypeError, "Only local variables are supported. To access storage variables,");
}
BOOST_AUTO_TEST_CASE(inline_assembly_storage_in_modifiers)
@ -5075,7 +5075,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_storage_in_modifiers)
}
}
)";
CHECK_ERROR(text, DeclarationError, "Variable not found or variable not lvalue.");
CHECK_ERROR(text, TypeError, "Only local variables are supported. To access storage variables,");
}
BOOST_AUTO_TEST_CASE(inline_assembly_constant_assign)
@ -5090,7 +5090,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_constant_assign)
}
}
)";
CHECK_ERROR(text, DeclarationError, "Variable not found or variable not lvalue.");
CHECK_ERROR(text, TypeError, "Constant variables not supported by inline assembly");
}
BOOST_AUTO_TEST_CASE(inline_assembly_constant_access)
@ -5105,7 +5105,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_constant_access)
}
}
)";
CHECK_ERROR(text, TypeError, "Constant variables not yet implemented for inline assembly");
CHECK_ERROR(text, TypeError, "Constant variables not supported by inline assembly");
}
BOOST_AUTO_TEST_CASE(invalid_mobile_type)