diff --git a/kclvm/parser/src/parser/stmt.rs b/kclvm/parser/src/parser/stmt.rs index dc31323c6..071e4a800 100644 --- a/kclvm/parser/src/parser/stmt.rs +++ b/kclvm/parser/src/parser/stmt.rs @@ -306,6 +306,7 @@ impl<'a> Parser<'a> { None } }) + // Drop error assign target nodes. .flatten() .collect(); @@ -369,6 +370,7 @@ impl<'a> Parser<'a> { None } }) + // Drop error assign target nodes. .flatten() .collect(); Some(Box::new(Node::node_with_pos( diff --git a/test/grammar/assign/assign_fail_2/main.k b/test/grammar/assign/assign_fail_2/main.k new file mode 100644 index 000000000..1ef8a0c15 --- /dev/null +++ b/test/grammar/assign/assign_fail_2/main.k @@ -0,0 +1,2 @@ +_a = [1, 2, 3] +_a[1:2] = [2, 3] \ No newline at end of file diff --git a/test/grammar/assign/assign_fail_2/stderr.golden b/test/grammar/assign/assign_fail_2/stderr.golden new file mode 100644 index 000000000..e282bf990 --- /dev/null +++ b/test/grammar/assign/assign_fail_2/stderr.golden @@ -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 \ No newline at end of file diff --git a/test/grammar/assign/assign_fail_3/main.k b/test/grammar/assign/assign_fail_3/main.k new file mode 100644 index 000000000..af839bf50 --- /dev/null +++ b/test/grammar/assign/assign_fail_3/main.k @@ -0,0 +1,2 @@ +_a = {} +_a?.b = "value" \ No newline at end of file diff --git a/test/grammar/assign/assign_fail_3/stderr.golden b/test/grammar/assign/assign_fail_3/stderr.golden new file mode 100644 index 000000000..f485aa623 --- /dev/null +++ b/test/grammar/assign/assign_fail_3/stderr.golden @@ -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. diff --git a/test/grammar/assign/assign_fail_4/main.k b/test/grammar/assign/assign_fail_4/main.k new file mode 100644 index 000000000..f1097573a --- /dev/null +++ b/test/grammar/assign/assign_fail_4/main.k @@ -0,0 +1 @@ +_a + 1 = 2 \ No newline at end of file diff --git a/test/grammar/assign/assign_fail_4/stderr.golden b/test/grammar/assign/assign_fail_4/stderr.golden new file mode 100644 index 000000000..af7a9f804 --- /dev/null +++ b/test/grammar/assign/assign_fail_4/stderr.golden @@ -0,0 +1 @@ +'BinaryExpression' is an illegal expression for assignment \ No newline at end of file diff --git a/test/grammar/assign/assign_fail_5/main.k b/test/grammar/assign/assign_fail_5/main.k new file mode 100644 index 000000000..ad7d54061 --- /dev/null +++ b/test/grammar/assign/assign_fail_5/main.k @@ -0,0 +1 @@ +[1] = 2 \ No newline at end of file diff --git a/test/grammar/assign/assign_fail_5/stderr.golden b/test/grammar/assign/assign_fail_5/stderr.golden new file mode 100644 index 000000000..9b88d5258 --- /dev/null +++ b/test/grammar/assign/assign_fail_5/stderr.golden @@ -0,0 +1 @@ +'ListExpression' is an illegal expression for assignment \ No newline at end of file diff --git a/test/grammar/assign/assign_fail_6/main.k b/test/grammar/assign/assign_fail_6/main.k new file mode 100644 index 000000000..41c9a8a35 --- /dev/null +++ b/test/grammar/assign/assign_fail_6/main.k @@ -0,0 +1 @@ +_f() = 2 \ No newline at end of file diff --git a/test/grammar/assign/assign_fail_6/stderr.golden b/test/grammar/assign/assign_fail_6/stderr.golden new file mode 100644 index 000000000..fc14ede0d --- /dev/null +++ b/test/grammar/assign/assign_fail_6/stderr.golden @@ -0,0 +1 @@ +'CallExpression' is an illegal expression for assignment \ No newline at end of file