Skip to content

Commit

Permalink
checker: disallow (x) := 10 (#20695)
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 committed Jan 30, 2024
1 parent afa1a9a commit 1dc5d36
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions vlib/v/checker/assign.v
Expand Up @@ -267,6 +267,11 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
}
}
node.left_types << left_type

if left is ast.ParExpr && is_decl {
c.error('parentheses are not supported on the left side of `:=`', left.pos())
}

for left is ast.ParExpr {
left = (left as ast.ParExpr).expr
}
Expand Down
5 changes: 5 additions & 0 deletions vlib/v/checker/tests/par_expr_decl_assign_err.out
@@ -0,0 +1,5 @@
vlib/v/checker/tests/par_expr_decl_assign_err.vv:2:2: error: parentheses are not supported on the left side of `:=`
1 | fn main() {
2 | (x) := 5
| ~~~
3 | }
3 changes: 3 additions & 0 deletions vlib/v/checker/tests/par_expr_decl_assign_err.vv
@@ -0,0 +1,3 @@
fn main() {
(x) := 5
}
6 changes: 6 additions & 0 deletions vlib/v/checker/tests/prefix_expr_decl_assign_err.out
Expand Up @@ -10,6 +10,12 @@ vlib/v/checker/tests/prefix_expr_decl_assign_err.vv:2:5: error: non-name on the
| ^
3 | (*d) := 14
4 | }
vlib/v/checker/tests/prefix_expr_decl_assign_err.vv:3:5: error: parentheses are not supported on the left side of `:=`
1 | fn main() {
2 | &a := 12
3 | (*d) := 14
| ~~~~
4 | }
vlib/v/checker/tests/prefix_expr_decl_assign_err.vv:3:10: error: modifying variables via dereferencing can only be done in `unsafe` blocks
1 | fn main() {
2 | &a := 12
Expand Down

0 comments on commit 1dc5d36

Please sign in to comment.