diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 519382d5f..f77368ce8 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -203,41 +203,6 @@ BOOST_AUTO_TEST_CASE(constants) BOOST_CHECK(successParse("{ pop(mul(7, 8)) }")); } -BOOST_AUTO_TEST_CASE(for_statement) -{ - BOOST_CHECK(successParse("{ for {} 1 {} {} }")); - BOOST_CHECK(successParse("{ for { let i := 1 } lt(i, 5) { i := add(i, 1) } {} }")); -} - -BOOST_AUTO_TEST_CASE(for_invalid_expression) -{ - CHECK_PARSE_ERROR("{ for {} {} {} {} }", ParserError, "Literal or identifier expected."); - CHECK_PARSE_ERROR("{ for 1 1 {} {} }", ParserError, "Expected '{' but got 'Number'"); - CHECK_PARSE_ERROR("{ for {} 1 1 {} }", ParserError, "Expected '{' but got 'Number'"); - CHECK_PARSE_ERROR("{ for {} 1 {} 1 }", ParserError, "Expected '{' but got 'Number'"); - CHECK_PARSE_ERROR("{ for {} mload {} {} }", ParserError, "Expected '(' but got '{'"); - CHECK_PARSE_ERROR("{ for {} mstore(1, 1) {} {} }", TypeError, "Expected expression to evaluate to one value, but got 0 values instead."); -} - -BOOST_AUTO_TEST_CASE(for_visibility) -{ - BOOST_CHECK(successParse("{ for { let i := 1 } i { pop(i) } { pop(i) } }")); - CHECK_PARSE_ERROR("{ for {} i { let i := 1 } {} }", DeclarationError, "Identifier not found"); - CHECK_PARSE_ERROR("{ for {} 1 { let i := 1 } { pop(i) } }", DeclarationError, "Identifier not found"); - CHECK_PARSE_ERROR("{ for {} 1 { pop(i) } { let i := 1 } }", DeclarationError, "Identifier not found"); - CHECK_PARSE_ERROR("{ for { pop(i) } 1 { let i := 1 } {} }", DeclarationError, "Identifier not found"); - CHECK_PARSE_ERROR("{ for { pop(i) } 1 { } { let i := 1 } }", DeclarationError, "Identifier not found"); - CHECK_PARSE_ERROR("{ for {} i {} { let i := 1 } }", DeclarationError, "Identifier not found"); - CHECK_PARSE_ERROR("{ for {} 1 { pop(i) } { let i := 1 } }", DeclarationError, "Identifier not found"); - CHECK_PARSE_ERROR("{ for { let x := 1 } 1 { let x := 1 } {} }", DeclarationError, "Variable name x already taken in this scope"); - CHECK_PARSE_ERROR("{ for { let x := 1 } 1 {} { let x := 1 } }", DeclarationError, "Variable name x already taken in this scope"); - CHECK_PARSE_ERROR("{ let x := 1 for { let x := 1 } 1 {} {} }", DeclarationError, "Variable name x already taken in this scope"); - CHECK_PARSE_ERROR("{ let x := 1 for {} 1 { let x := 1 } {} }", DeclarationError, "Variable name x already taken in this scope"); - CHECK_PARSE_ERROR("{ let x := 1 for {} 1 {} { let x := 1 } }", DeclarationError, "Variable name x already taken in this scope"); - // Check that body and post are not sub-scopes of each other. - BOOST_CHECK(successParse("{ for {} 1 { let x := 1 } { let x := 1 } }")); -} - BOOST_AUTO_TEST_CASE(blocks) { BOOST_CHECK(successParse("{ let x := 7 { let y := 3 } { let z := 2 } }")); @@ -512,12 +477,6 @@ BOOST_AUTO_TEST_CASE(embedded_functions) BOOST_CHECK(successAssemble("{ function f(r, s) -> x { function g(a) -> b { } x := g(2) } let x := f(2, 3) }")); } -BOOST_AUTO_TEST_CASE(for_statement) -{ - BOOST_CHECK(successAssemble("{ for {} 1 {} {} }")); - BOOST_CHECK(successAssemble("{ let x := calldatasize() for { let i := 0} lt(i, x) { i := add(i, 1) } { mstore(i, 2) } }")); -} - BOOST_AUTO_TEST_CASE(large_constant) { auto source = R"({ diff --git a/test/libyul/yulSyntaxTests/for_expr_invalid_1.yul b/test/libyul/yulSyntaxTests/for_expr_invalid_1.yul new file mode 100644 index 000000000..00f0a4d58 --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_expr_invalid_1.yul @@ -0,0 +1,5 @@ +{ + for {} {} {} {} +} +// ---- +// ParserError 1856: (10-11): Literal or identifier expected. diff --git a/test/libyul/yulSyntaxTests/for_expr_invalid_2.yul b/test/libyul/yulSyntaxTests/for_expr_invalid_2.yul new file mode 100644 index 000000000..d4d801204 --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_expr_invalid_2.yul @@ -0,0 +1,5 @@ +{ + for 1 1 {} {} +} +// ---- +// ParserError 2314: (7-8): Expected '{' but got 'Number' diff --git a/test/libyul/yulSyntaxTests/for_expr_invalid_3.yul b/test/libyul/yulSyntaxTests/for_expr_invalid_3.yul new file mode 100644 index 000000000..8f8268659 --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_expr_invalid_3.yul @@ -0,0 +1,5 @@ +{ + for {} 1 1 {} +} +// ---- +// ParserError 2314: (12-13): Expected '{' but got 'Number' diff --git a/test/libyul/yulSyntaxTests/for_expr_invalid_4.yul b/test/libyul/yulSyntaxTests/for_expr_invalid_4.yul new file mode 100644 index 000000000..abd2260d7 --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_expr_invalid_4.yul @@ -0,0 +1,5 @@ +{ + for {} 1 {} 1 +} +// ---- +// ParserError 2314: (15-16): Expected '{' but got 'Number' diff --git a/test/libyul/yulSyntaxTests/for_expr_invalid_5.yul b/test/libyul/yulSyntaxTests/for_expr_invalid_5.yul new file mode 100644 index 000000000..acf9be847 --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_expr_invalid_5.yul @@ -0,0 +1,5 @@ +{ + for {} mload {} {} +} +// ---- +// ParserError 2314: (16-17): Expected '(' but got '{' diff --git a/test/libyul/yulSyntaxTests/for_expr_invalid_6.yul b/test/libyul/yulSyntaxTests/for_expr_invalid_6.yul new file mode 100644 index 000000000..42883052e --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_expr_invalid_6.yul @@ -0,0 +1,7 @@ +{ + for {} mstore(1, 1) {} {} +} +// ==== +// dialect: evm +// ---- +// TypeError 3950: (10-22): Expected expression to evaluate to one value, but got 0 values instead. diff --git a/test/libyul/yulSyntaxTests/for_statement_2.yul b/test/libyul/yulSyntaxTests/for_statement_2.yul new file mode 100644 index 000000000..1c74f4239 --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_statement_2.yul @@ -0,0 +1,10 @@ +{ + + { for {} 1 {} {} } + { for { let i := 1 } lt(i, 5) { i := add(i, 1) } {} } + { for {} 1 {} {} } + { let x := calldatasize() for { let i := 0} lt(i, x) { i := add(i, 1) } { mstore(i, 2) } } +} +// ==== +// dialect: evm +// ---- diff --git a/test/libyul/yulSyntaxTests/for_visibility_1.yul b/test/libyul/yulSyntaxTests/for_visibility_1.yul new file mode 100644 index 000000000..05d876335 --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_visibility_1.yul @@ -0,0 +1,5 @@ +{ + for { let i := 1 } i { pop(i) } { pop(i) } +} +// ==== +// dialect: evm diff --git a/test/libyul/yulSyntaxTests/for_visibility_2.yul b/test/libyul/yulSyntaxTests/for_visibility_2.yul new file mode 100644 index 000000000..62cc90c0c --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_visibility_2.yul @@ -0,0 +1,7 @@ +{ + for {} i { let i := 1 } {} +} +// ==== +// dialect: evm +// ---- +// DeclarationError 8198: (10-11): Identifier not found. diff --git a/test/libyul/yulSyntaxTests/for_visibility_3.yul b/test/libyul/yulSyntaxTests/for_visibility_3.yul new file mode 100644 index 000000000..54af2f854 --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_visibility_3.yul @@ -0,0 +1,7 @@ +{ + for {} 1 { let i := 1 } { pop(i) } +} +// ==== +// dialect: evm +// ---- +// DeclarationError 8198: (33-34): Identifier not found. diff --git a/test/libyul/yulSyntaxTests/for_visibility_4.yul b/test/libyul/yulSyntaxTests/for_visibility_4.yul new file mode 100644 index 000000000..68e81f3b4 --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_visibility_4.yul @@ -0,0 +1,7 @@ +{ + for {} 1 { pop(i) } { let i := 1 } +} +// ==== +// dialect: evm +// ---- +// DeclarationError 8198: (18-19): Identifier not found. diff --git a/test/libyul/yulSyntaxTests/for_visibility_5.yul b/test/libyul/yulSyntaxTests/for_visibility_5.yul new file mode 100644 index 000000000..2785394d8 --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_visibility_5.yul @@ -0,0 +1,7 @@ +{ + for { pop(i) } 1 { let i := 1 } {} +} +// ==== +// dialect: evm +// ---- +// DeclarationError 8198: (13-14): Identifier not found. diff --git a/test/libyul/yulSyntaxTests/for_visibility_6.yul b/test/libyul/yulSyntaxTests/for_visibility_6.yul new file mode 100644 index 000000000..75cb6d531 --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_visibility_6.yul @@ -0,0 +1,7 @@ +{ + for { pop(i) } 1 { } { let i := 1 } +} +// ==== +// dialect: evm +// ---- +// DeclarationError 8198: (13-14): Identifier not found. diff --git a/test/libyul/yulSyntaxTests/for_visibility_7.yul b/test/libyul/yulSyntaxTests/for_visibility_7.yul new file mode 100644 index 000000000..00e289714 --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_visibility_7.yul @@ -0,0 +1,7 @@ +{ + for {} i {} { let i := 1 } +} +// ==== +// dialect: evm +// ---- +// DeclarationError 8198: (10-11): Identifier not found. diff --git a/test/libyul/yulSyntaxTests/for_visibility_8.yul b/test/libyul/yulSyntaxTests/for_visibility_8.yul new file mode 100644 index 000000000..68e81f3b4 --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_visibility_8.yul @@ -0,0 +1,7 @@ +{ + for {} 1 { pop(i) } { let i := 1 } +} +// ==== +// dialect: evm +// ---- +// DeclarationError 8198: (18-19): Identifier not found. diff --git a/test/libyul/yulSyntaxTests/for_visibility_9.yul b/test/libyul/yulSyntaxTests/for_visibility_9.yul new file mode 100644 index 000000000..4cda1b165 --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_visibility_9.yul @@ -0,0 +1,7 @@ +{ + for { let x := 1 } 1 { let x := 1 } {} +} +// ==== +// dialect: yul +// ---- +// DeclarationError 1395: (26-36): Variable name x already taken in this scope. diff --git a/test/libyul/yulSyntaxTests/for_visibility_A.yul b/test/libyul/yulSyntaxTests/for_visibility_A.yul new file mode 100644 index 000000000..a5761f52a --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_visibility_A.yul @@ -0,0 +1,7 @@ +{ + for { let x := 1 } 1 {} { let x := 1 } +} +// ==== +// dialect: yul +// ---- +// DeclarationError 1395: (29-39): Variable name x already taken in this scope. diff --git a/test/libyul/yulSyntaxTests/for_visibility_B.yul b/test/libyul/yulSyntaxTests/for_visibility_B.yul new file mode 100644 index 000000000..d315a611d --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_visibility_B.yul @@ -0,0 +1,5 @@ +{ + let x := 1 for { let x := 1 } 1 {} {} +} +// ---- +// DeclarationError 1395: (20-30): Variable name x already taken in this scope. diff --git a/test/libyul/yulSyntaxTests/for_visibility_C.yul b/test/libyul/yulSyntaxTests/for_visibility_C.yul new file mode 100644 index 000000000..81741fe7b --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_visibility_C.yul @@ -0,0 +1,5 @@ +{ + let x := 1 for {} 1 { let x := 1 } {} +} +// ---- +// DeclarationError 1395: (25-35): Variable name x already taken in this scope. diff --git a/test/libyul/yulSyntaxTests/for_visibility_D.yul b/test/libyul/yulSyntaxTests/for_visibility_D.yul new file mode 100644 index 000000000..409b10399 --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_visibility_D.yul @@ -0,0 +1,5 @@ +{ + let x := 1 for {} 1 {} { let x := 1 } +} +// ---- +// DeclarationError 1395: (28-38): Variable name x already taken in this scope. diff --git a/test/libyul/yulSyntaxTests/for_visibility_E.yul b/test/libyul/yulSyntaxTests/for_visibility_E.yul new file mode 100644 index 000000000..1f09cd34a --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_visibility_E.yul @@ -0,0 +1,6 @@ +{ + // Check that body and post are not sub-scopes of each other. + for {} 1 { let x := 1 } { let x := 1 } +} +// ==== +// dialect: evm