checker: add error for ast.PrefixExpr on the left side of decl_assign (#6660)
parent
d67e177733
commit
019e3b2f4a
|
@ -1975,6 +1975,9 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
|
||||||
c.error('modifying variables via dereferencing can only be done in `unsafe` blocks',
|
c.error('modifying variables via dereferencing can only be done in `unsafe` blocks',
|
||||||
assign_stmt.pos)
|
assign_stmt.pos)
|
||||||
}
|
}
|
||||||
|
if is_decl {
|
||||||
|
c.error('non-name on the left side of `:=`', left.pos)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if is_decl {
|
if is_decl {
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
vlib/v/checker/tests/prefix_expr_decl_assign_err.vv:2:5: error: non-name 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:1:1: error: non-name `(*d)` on left side of `:=`
|
||||||
|
1 | fn main() {
|
||||||
|
| ^
|
||||||
|
2 | &a := 12
|
||||||
|
3 | (*d) := 14
|
|
@ -0,0 +1,4 @@
|
||||||
|
fn main() {
|
||||||
|
&a := 12
|
||||||
|
(*d) := 14
|
||||||
|
}
|
|
@ -60,7 +60,7 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
|
||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
.minus, .amp, .mul, .not, .bit_not, .arrow {
|
.minus, .amp, .mul, .not, .bit_not, .arrow {
|
||||||
// -1, -a, !x, &x, ~x
|
// -1, -a, !x, &x, ~x, <-a
|
||||||
node = p.prefix_expr()
|
node = p.prefix_expr()
|
||||||
}
|
}
|
||||||
.key_true, .key_false {
|
.key_true, .key_false {
|
||||||
|
|
Loading…
Reference in New Issue