From 6f872dbebf45e5970b434ee5f9f8fff1efbcbfc2 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Mon, 19 Oct 2020 13:47:15 +0200 Subject: [PATCH] InlineAssembly: Extracting tests for if statement --- test/libsolidity/InlineAssembly.cpp | 27 ------------------- test/libyul/yulSyntaxTests/if_statement.yul | 8 ++++++ .../yulSyntaxTests/if_statement_invalid_1.yul | 5 ++++ .../yulSyntaxTests/if_statement_invalid_2.yul | 7 +++++ .../yulSyntaxTests/if_statement_invalid_3.yul | 7 +++++ .../yulSyntaxTests/if_statement_invalid_4.yul | 5 ++++ .../yulSyntaxTests/if_statement_scope_1.yul | 6 +++++ .../yulSyntaxTests/if_statement_scope_2.yul | 8 ++++++ 8 files changed, 46 insertions(+), 27 deletions(-) create mode 100644 test/libyul/yulSyntaxTests/if_statement.yul create mode 100644 test/libyul/yulSyntaxTests/if_statement_invalid_1.yul create mode 100644 test/libyul/yulSyntaxTests/if_statement_invalid_2.yul create mode 100644 test/libyul/yulSyntaxTests/if_statement_invalid_3.yul create mode 100644 test/libyul/yulSyntaxTests/if_statement_invalid_4.yul create mode 100644 test/libyul/yulSyntaxTests/if_statement_scope_1.yul create mode 100644 test/libyul/yulSyntaxTests/if_statement_scope_2.yul diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 1d61484a9..cd0606ed7 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -270,27 +270,6 @@ BOOST_AUTO_TEST_CASE(variable_use_before_decl) CHECK_PARSE_ERROR("{ let x := mul(2, x) }", DeclarationError, "Variable x used before it was declared."); } -BOOST_AUTO_TEST_CASE(if_statement) -{ - BOOST_CHECK(successParse("{ if 42 {} }")); - BOOST_CHECK(successParse("{ if 42 { let x := 3 } }")); - BOOST_CHECK(successParse("{ function f() -> x {} if f() { pop(f()) } }")); -} - -BOOST_AUTO_TEST_CASE(if_statement_scope) -{ - BOOST_CHECK(successParse("{ let x := 2 if 42 { x := 3 } }")); - CHECK_PARSE_ERROR("{ if 32 { let x := 3 } x := 2 }", DeclarationError, "Variable not found or variable not lvalue."); -} - -BOOST_AUTO_TEST_CASE(if_statement_invalid) -{ - CHECK_PARSE_ERROR("{ if mload {} }", ParserError, "Expected '(' but got '{'"); - BOOST_CHECK("{ if calldatasize() {}"); - CHECK_PARSE_ERROR("{ if mstore(1, 1) {} }", TypeError, "Expected expression to evaluate to one value, but got 0 values instead."); - CHECK_PARSE_ERROR("{ if 32 let x := 3 }", ParserError, "Expected '{' but got reserved keyword 'let'"); -} - BOOST_AUTO_TEST_CASE(switch_statement) { BOOST_CHECK(successParse("{ switch 42 default {} }")); @@ -671,12 +650,6 @@ BOOST_AUTO_TEST_CASE(for_statement) BOOST_CHECK(successAssemble("{ let x := calldatasize() for { let i := 0} lt(i, x) { i := add(i, 1) } { mstore(i, 2) } }")); } -BOOST_AUTO_TEST_CASE(if_statement) -{ - BOOST_CHECK(successAssemble("{ if 1 {} }")); - BOOST_CHECK(successAssemble("{ let x := 0 if eq(calldatasize(), 0) { x := 1 } mstore(0, x) }")); -} - BOOST_AUTO_TEST_CASE(large_constant) { auto source = R"({ diff --git a/test/libyul/yulSyntaxTests/if_statement.yul b/test/libyul/yulSyntaxTests/if_statement.yul new file mode 100644 index 000000000..6865a1b42 --- /dev/null +++ b/test/libyul/yulSyntaxTests/if_statement.yul @@ -0,0 +1,8 @@ +{ + { if 42 {} } + { if 42 { let x := 3 } } + { function f() -> x {} if f() { pop(f()) } } + { let x := 0 if eq(calldatasize(), 0) { x := 1 } mstore(0, x) } +} +// ==== +// dialect: evm diff --git a/test/libyul/yulSyntaxTests/if_statement_invalid_1.yul b/test/libyul/yulSyntaxTests/if_statement_invalid_1.yul new file mode 100644 index 000000000..5f73fcf2a --- /dev/null +++ b/test/libyul/yulSyntaxTests/if_statement_invalid_1.yul @@ -0,0 +1,5 @@ +{ + if mload {} +} +// ---- +// ParserError 2314: (15-16): Expected '(' but got '{' diff --git a/test/libyul/yulSyntaxTests/if_statement_invalid_2.yul b/test/libyul/yulSyntaxTests/if_statement_invalid_2.yul new file mode 100644 index 000000000..4e7970490 --- /dev/null +++ b/test/libyul/yulSyntaxTests/if_statement_invalid_2.yul @@ -0,0 +1,7 @@ +{ + if mstore(1, 1) {} +} +// ==== +// dialect: evm +// ---- +// TypeError 3950: (6-18): Expected expression to evaluate to one value, but got 0 values instead. diff --git a/test/libyul/yulSyntaxTests/if_statement_invalid_3.yul b/test/libyul/yulSyntaxTests/if_statement_invalid_3.yul new file mode 100644 index 000000000..fa396456f --- /dev/null +++ b/test/libyul/yulSyntaxTests/if_statement_invalid_3.yul @@ -0,0 +1,7 @@ +{ + if 32 let x := 3 +} +// ==== +// dialect: yul +// ---- +// ParserError 2314: (12-15): Expected '{' but got reserved keyword 'let' diff --git a/test/libyul/yulSyntaxTests/if_statement_invalid_4.yul b/test/libyul/yulSyntaxTests/if_statement_invalid_4.yul new file mode 100644 index 000000000..ed9deeda6 --- /dev/null +++ b/test/libyul/yulSyntaxTests/if_statement_invalid_4.yul @@ -0,0 +1,5 @@ +{ + if calldatasize {} +} +// ---- +// ParserError 2314: (22-23): Expected '(' but got '{' diff --git a/test/libyul/yulSyntaxTests/if_statement_scope_1.yul b/test/libyul/yulSyntaxTests/if_statement_scope_1.yul new file mode 100644 index 000000000..3b49e4703 --- /dev/null +++ b/test/libyul/yulSyntaxTests/if_statement_scope_1.yul @@ -0,0 +1,6 @@ +{ + let x := 2 + if 42 { x := 3 } +} +// ==== +// dialect: evm diff --git a/test/libyul/yulSyntaxTests/if_statement_scope_2.yul b/test/libyul/yulSyntaxTests/if_statement_scope_2.yul new file mode 100644 index 000000000..e86578812 --- /dev/null +++ b/test/libyul/yulSyntaxTests/if_statement_scope_2.yul @@ -0,0 +1,8 @@ +{ + if 32 { let x := 3 } + x := 2 +} +// ==== +// dialect: evm +// ---- +// DeclarationError 4634: (25-26): Variable not found or variable not lvalue.