1
0
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:
Swastik Baranwal 2023-05-08 04:56:36 +05:30 committed by GitHub
parent b50dac5e9a
commit 5bdf94a7bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 18 additions and 0 deletions

View File

@ -2077,6 +2077,10 @@ fn (mut p Parser) parse_multi_expr(is_top_level bool) ast.Stmt {
p.defer_vars = defer_vars p.defer_vars = defer_vars
left0 := left[0] 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 { if tok.kind == .key_mut && p.tok.kind != .decl_assign {
return p.error('expecting `:=` (e.g. `mut x :=`)') return p.error('expecting `:=` (e.g. `mut x :=`)')
} }

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

View File

@ -0,0 +1,2 @@
atomic _ = 3

View File

@ -0,0 +1,3 @@
vlib/v/parser/tests/mut_blank_ident_err.vv:1:1: error: cannot use `mut` on `_`
1 | mut _ = 3
| ~~~

View File

@ -0,0 +1 @@
mut _ = 3

View File

@ -0,0 +1,3 @@
vlib/v/parser/tests/shared_blank_ident_err.vv:1:1: error: cannot use `shared` on `_`
1 | shared _ = 3
| ~~~~~~

View File

@ -0,0 +1 @@
shared _ = 3