checker: add error for ast.PrefixExpr on the left side of decl_assign (#6660)

pull/6666/head
Swastik Baranwal 2020-10-21 21:07:30 +05:30 committed by GitHub
parent d67e177733
commit 019e3b2f4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 1 deletions

View File

@ -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',
assign_stmt.pos)
}
if is_decl {
c.error('non-name on the left side of `:=`', left.pos)
}
}
else {
if is_decl {

View File

@ -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

View File

@ -0,0 +1,4 @@
fn main() {
&a := 12
(*d) := 14
}

View File

@ -60,7 +60,7 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
p.next()
}
.minus, .amp, .mul, .not, .bit_not, .arrow {
// -1, -a, !x, &x, ~x
// -1, -a, !x, &x, ~x, <-a
node = p.prefix_expr()
}
.key_true, .key_false {