Skip to content

Commit

Permalink
test: add more error test cases on wrong assign targets
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Jul 19, 2024
1 parent 9e7c0d2 commit 3612087
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kclvm/parser/src/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ impl<'a> Parser<'a> {
None
}
})
// Drop error assign target nodes.
.flatten()
.collect();

Expand Down Expand Up @@ -369,6 +370,7 @@ impl<'a> Parser<'a> {
None
}
})
// Drop error assign target nodes.
.flatten()
.collect();
Some(Box::new(Node::node_with_pos(
Expand Down
2 changes: 2 additions & 0 deletions test/grammar/assign/assign_fail_2/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_a = [1, 2, 3]
_a[1:2] = [2, 3]
1 change: 1 addition & 0 deletions test/grammar/assign/assign_fail_2/stderr.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'SubscriptExpression' is an illegal expression for assignment, because the left-hand side of an assignment expression may not be a slice access
2 changes: 2 additions & 0 deletions test/grammar/assign/assign_fail_3/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_a = {}
_a?.b = "value"
1 change: 1 addition & 0 deletions test/grammar/assign/assign_fail_3/stderr.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'SelectorExpression' is an illegal expression for assignment, because the left-hand side of an assignment expression may not be an optional attribute access.
1 change: 1 addition & 0 deletions test/grammar/assign/assign_fail_4/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_a + 1 = 2
1 change: 1 addition & 0 deletions test/grammar/assign/assign_fail_4/stderr.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'BinaryExpression' is an illegal expression for assignment
1 change: 1 addition & 0 deletions test/grammar/assign/assign_fail_5/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1] = 2
1 change: 1 addition & 0 deletions test/grammar/assign/assign_fail_5/stderr.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'ListExpression' is an illegal expression for assignment
1 change: 1 addition & 0 deletions test/grammar/assign/assign_fail_6/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_f() = 2
1 change: 1 addition & 0 deletions test/grammar/assign/assign_fail_6/stderr.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'CallExpression' is an illegal expression for assignment

0 comments on commit 3612087

Please sign in to comment.