diff options
author | chriseth <chris@ethereum.org> | 2017-04-25 19:15:42 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2017-04-25 22:49:04 +0800 |
commit | 1d712c7d6490616846de4ec9569ca627e62ea2c1 (patch) | |
tree | f3036aaab6076f6248148db9be9f92aa540055ac | |
parent | e841b23bfd57607511d620ed34ef96188bbadec6 (diff) | |
download | dexon-solidity-1d712c7d6490616846de4ec9569ca627e62ea2c1.tar.gz dexon-solidity-1d712c7d6490616846de4ec9569ca627e62ea2c1.tar.zst dexon-solidity-1d712c7d6490616846de4ec9569ca627e62ea2c1.zip |
Fix storage access tests.
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 10 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmAnalysis.cpp | 26 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 10 |
3 files changed, 26 insertions, 20 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index b07dbde1..08a49f51 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -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) { diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libsolidity/inlineasm/AsmAnalysis.cpp index 80cabe2e..97ec8b1f 100644 --- a/libsolidity/inlineasm/AsmAnalysis.cpp +++ b/libsolidity/inlineasm/AsmAnalysis.cpp @@ -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)) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 73698a8d..f88f600a 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -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) |