mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: disallow invalid prefix on left side of assign stmt (#18750)
This commit is contained in:
parent
df3c85eb36
commit
ab258aebfb
@ -392,6 +392,11 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
||||
left.right.obj.is_used = true
|
||||
}
|
||||
}
|
||||
} else if left.op == .amp {
|
||||
c.error('cannot use a reference on the left side of `${node.op}`',
|
||||
left.pos)
|
||||
} else {
|
||||
c.error('cannot use `${left.op}` on the left of `${node.op}`', left.pos)
|
||||
}
|
||||
if is_decl {
|
||||
c.error('non-name on the left side of `:=`', left.pos)
|
||||
|
@ -0,0 +1,14 @@
|
||||
vlib/v/checker/tests/invalid_prefix_left_side_assign_stmt_err.vv:3:2: error: cannot use `~` on the left of `=`
|
||||
1 | fn main() {
|
||||
2 | mut x := 0
|
||||
3 | ~x = 34
|
||||
| ^
|
||||
4 | &x = unsafe { nil }
|
||||
5 | println(x)
|
||||
vlib/v/checker/tests/invalid_prefix_left_side_assign_stmt_err.vv:4:2: error: cannot use a reference on the left side of `=`
|
||||
2 | mut x := 0
|
||||
3 | ~x = 34
|
||||
4 | &x = unsafe { nil }
|
||||
| ^
|
||||
5 | println(x)
|
||||
6 | }
|
@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
mut x := 0
|
||||
~x = 34
|
||||
&x = unsafe { nil }
|
||||
println(x)
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
vlib/v/checker/tests/prefix_expr_decl_assign_err.vv:2:5: error: non-name on the left side of `:=`
|
||||
vlib/v/checker/tests/prefix_expr_decl_assign_err.vv:2:5: error: cannot use a reference on the left side of `:=`
|
||||
1 | fn main() {
|
||||
2 | &a := 12
|
||||
| ^
|
||||
|
Loading…
Reference in New Issue
Block a user