aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-05-24 21:03:49 +0800
committerGitHub <noreply@github.com>2017-05-24 21:03:49 +0800
commitafe0a5404f4012650e6bea1f2ac0696dc464e2d1 (patch)
tree404fd5f4f71b470c7172a36d2fc35ffbe601b2b1
parent451acd4c9f118a299e627d574dee1785d870723a (diff)
parent338202ea96e0af8822dde3acc27aa45f79c8780b (diff)
downloaddexon-solidity-afe0a5404f4012650e6bea1f2ac0696dc464e2d1.tar.gz
dexon-solidity-afe0a5404f4012650e6bea1f2ac0696dc464e2d1.tar.zst
dexon-solidity-afe0a5404f4012650e6bea1f2ac0696dc464e2d1.zip
Merge pull request #2302 from ethereum/inlineasm-better-errors
Better error messages for parsing functional assembly instructions
-rw-r--r--Changelog.md4
-rw-r--r--libsolidity/inlineasm/AsmParser.cpp10
-rw-r--r--test/libsolidity/InlineAssembly.cpp11
3 files changed, 25 insertions, 0 deletions
diff --git a/Changelog.md b/Changelog.md
index 2073c0a4..5ba712f5 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,5 +1,9 @@
### 0.4.12 (unreleased)
+
+Features:
* AST: export all attributes to Json format
+ * Inline Assembly: Present proper error message when not supplying enough arguments to a functional
+ instruction.
Bugfixes:
* Unused variable warnings no longer issued for variables used inside inline assembly
diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp
index 85ae9424..530cd726 100644
--- a/libsolidity/inlineasm/AsmParser.cpp
+++ b/libsolidity/inlineasm/AsmParser.cpp
@@ -321,6 +321,16 @@ assembly::Statement Parser::parseCall(assembly::Statement&& _instruction)
unsigned args = unsigned(instrInfo.args);
for (unsigned i = 0; i < args; ++i)
{
+ /// check for premature closing parentheses
+ if (m_scanner->currentToken() == Token::RParen)
+ fatalParserError(string(
+ "Expected expression (" +
+ instrInfo.name +
+ " expects " +
+ boost::lexical_cast<string>(args) +
+ " arguments)"
+ ));
+
ret.arguments.emplace_back(parseExpression());
if (i != args - 1)
{
diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp
index f155cba7..61892761 100644
--- a/test/libsolidity/InlineAssembly.cpp
+++ b/test/libsolidity/InlineAssembly.cpp
@@ -270,6 +270,17 @@ BOOST_AUTO_TEST_CASE(invalid_tuple_assignment)
CHECK_PARSE_ERROR("{ 42 let x, y := 1 }", DeclarationError, "Variable count mismatch.");
}
+BOOST_AUTO_TEST_CASE(instruction_too_few_arguments)
+{
+ CHECK_PARSE_ERROR("{ mul() }", ParserError, "Expected expression (MUL expects 2 arguments)");
+ CHECK_PARSE_ERROR("{ mul(1) }", ParserError, "Expected comma (MUL expects 2 arguments)");
+}
+
+BOOST_AUTO_TEST_CASE(instruction_too_many_arguments)
+{
+ CHECK_PARSE_ERROR("{ mul(1, 2, 3) }", ParserError, "Expected ')' (MUL expects 2 arguments)");
+}
+
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(Printing)