mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: disallow mut for blank idents (#18114)
This commit is contained in:
parent
b50dac5e9a
commit
5bdf94a7bc
@ -2077,6 +2077,10 @@ fn (mut p Parser) parse_multi_expr(is_top_level bool) ast.Stmt {
|
||||
p.defer_vars = defer_vars
|
||||
|
||||
left0 := left[0]
|
||||
if tok.kind in [.key_mut, .key_shared, .key_atomic] && left0.is_blank_ident() {
|
||||
return p.error_with_pos('cannot use `${tok.kind}` on `_`', tok.pos())
|
||||
}
|
||||
|
||||
if tok.kind == .key_mut && p.tok.kind != .decl_assign {
|
||||
return p.error('expecting `:=` (e.g. `mut x :=`)')
|
||||
}
|
||||
|
4
vlib/v/parser/tests/atomic_blank_ident_err.out
Normal file
4
vlib/v/parser/tests/atomic_blank_ident_err.out
Normal file
@ -0,0 +1,4 @@
|
||||
vlib/v/parser/tests/atomic_blank_ident_err.vv:1:1: error: cannot use `atomic` on `_`
|
||||
1 | atomic _ = 3
|
||||
| ~~~~~~
|
||||
2 |
|
2
vlib/v/parser/tests/atomic_blank_ident_err.vv
Normal file
2
vlib/v/parser/tests/atomic_blank_ident_err.vv
Normal file
@ -0,0 +1,2 @@
|
||||
atomic _ = 3
|
||||
|
3
vlib/v/parser/tests/mut_blank_ident_err.out
Normal file
3
vlib/v/parser/tests/mut_blank_ident_err.out
Normal file
@ -0,0 +1,3 @@
|
||||
vlib/v/parser/tests/mut_blank_ident_err.vv:1:1: error: cannot use `mut` on `_`
|
||||
1 | mut _ = 3
|
||||
| ~~~
|
1
vlib/v/parser/tests/mut_blank_ident_err.vv
Normal file
1
vlib/v/parser/tests/mut_blank_ident_err.vv
Normal file
@ -0,0 +1 @@
|
||||
mut _ = 3
|
3
vlib/v/parser/tests/shared_blank_ident_err.out
Normal file
3
vlib/v/parser/tests/shared_blank_ident_err.out
Normal file
@ -0,0 +1,3 @@
|
||||
vlib/v/parser/tests/shared_blank_ident_err.vv:1:1: error: cannot use `shared` on `_`
|
||||
1 | shared _ = 3
|
||||
| ~~~~~~
|
1
vlib/v/parser/tests/shared_blank_ident_err.vv
Normal file
1
vlib/v/parser/tests/shared_blank_ident_err.vv
Normal file
@ -0,0 +1 @@
|
||||
shared _ = 3
|
Loading…
Reference in New Issue
Block a user