mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: check using invalid keyword with none ident (#13743)
This commit is contained in:
parent
78b1cbefff
commit
1d83ab6be1
|
@ -1943,6 +1943,7 @@ pub fn (mut p Parser) parse_ident(language ast.Language) ast.Ident {
|
||||||
p.register_auto_import('sync')
|
p.register_auto_import('sync')
|
||||||
}
|
}
|
||||||
mut_pos := p.tok.pos()
|
mut_pos := p.tok.pos()
|
||||||
|
kind_name := '$p.tok.kind'
|
||||||
is_mut := p.tok.kind == .key_mut || is_shared || is_atomic
|
is_mut := p.tok.kind == .key_mut || is_shared || is_atomic
|
||||||
if is_mut {
|
if is_mut {
|
||||||
p.next()
|
p.next()
|
||||||
|
@ -1956,7 +1957,11 @@ pub fn (mut p Parser) parse_ident(language ast.Language) ast.Ident {
|
||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
if p.tok.kind != .name {
|
if p.tok.kind != .name {
|
||||||
p.error('unexpected token `$p.tok.lit`')
|
if is_mut || is_static || is_volatile {
|
||||||
|
p.error_with_pos('the `$kind_name` keyword is invalid here', mut_pos)
|
||||||
|
} else {
|
||||||
|
p.error('unexpected token `$p.tok.lit`')
|
||||||
|
}
|
||||||
return ast.Ident{
|
return ast.Ident{
|
||||||
scope: p.scope
|
scope: p.scope
|
||||||
}
|
}
|
||||||
|
|
6
vlib/v/parser/tests/invalid_using_atomic.out
Normal file
6
vlib/v/parser/tests/invalid_using_atomic.out
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
vlib/v/parser/tests/invalid_using_atomic.vv:2:5: error: the `atomic` keyword is invalid here
|
||||||
|
1 | fn main() {
|
||||||
|
2 | if atomic true {
|
||||||
|
| ~~~~~~
|
||||||
|
3 | println(true)
|
||||||
|
4 | }
|
5
vlib/v/parser/tests/invalid_using_atomic.vv
Normal file
5
vlib/v/parser/tests/invalid_using_atomic.vv
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
fn main() {
|
||||||
|
if atomic true {
|
||||||
|
println(true)
|
||||||
|
}
|
||||||
|
}
|
6
vlib/v/parser/tests/invalid_using_mut.out
Normal file
6
vlib/v/parser/tests/invalid_using_mut.out
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
vlib/v/parser/tests/invalid_using_mut.vv:2:5: error: the `mut` keyword is invalid here
|
||||||
|
1 | fn main() {
|
||||||
|
2 | if mut true {
|
||||||
|
| ~~~
|
||||||
|
3 | println(true)
|
||||||
|
4 | }
|
6
vlib/v/parser/tests/invalid_using_shared.out
Normal file
6
vlib/v/parser/tests/invalid_using_shared.out
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
vlib/v/parser/tests/invalid_using_shared.vv:2:5: error: the `shared` keyword is invalid here
|
||||||
|
1 | fn main() {
|
||||||
|
2 | if shared true {
|
||||||
|
| ~~~~~~
|
||||||
|
3 | println(true)
|
||||||
|
4 | }
|
5
vlib/v/parser/tests/invalid_using_shared.vv
Normal file
5
vlib/v/parser/tests/invalid_using_shared.vv
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
fn main() {
|
||||||
|
if shared true {
|
||||||
|
println(true)
|
||||||
|
}
|
||||||
|
}
|
6
vlib/v/parser/tests/invalid_using_static.out
Normal file
6
vlib/v/parser/tests/invalid_using_static.out
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
vlib/v/parser/tests/invalid_using_static.vv:2:5: error: the `static` keyword is invalid here
|
||||||
|
1 | fn main() {
|
||||||
|
2 | if static true {
|
||||||
|
| ~~~~~~
|
||||||
|
3 | println(true)
|
||||||
|
4 | }
|
5
vlib/v/parser/tests/invalid_using_static.vv
Normal file
5
vlib/v/parser/tests/invalid_using_static.vv
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
fn main() {
|
||||||
|
if static true {
|
||||||
|
println(true)
|
||||||
|
}
|
||||||
|
}
|
6
vlib/v/parser/tests/invalid_using_volatile.out
Normal file
6
vlib/v/parser/tests/invalid_using_volatile.out
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
vlib/v/parser/tests/invalid_using_volatile.vv:2:5: error: the `volatile` keyword is invalid here
|
||||||
|
1 | fn main() {
|
||||||
|
2 | if volatile true {
|
||||||
|
| ~~~~~~~~
|
||||||
|
3 | println(true)
|
||||||
|
4 | }
|
5
vlib/v/parser/tests/invalid_using_volatile.vv
Normal file
5
vlib/v/parser/tests/invalid_using_volatile.vv
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
fn main() {
|
||||||
|
if volatile true {
|
||||||
|
println(true)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +0,0 @@
|
||||||
vlib/v/parser/tests/unnecessary_mut_2.vv:2:9: error: unexpected token `true`
|
|
||||||
1 | fn main() {
|
|
||||||
2 | if mut true {
|
|
||||||
| ~~~~
|
|
||||||
3 | println(true)
|
|
||||||
4 | }
|
|
Loading…
Reference in New Issue
Block a user