mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: add proper error msg for :=
used in const decl (#16607)
This commit is contained in:
parent
921416d821
commit
bb705c01d2
@ -3555,6 +3555,9 @@ fn (mut p Parser) const_decl() ast.ConstDecl {
|
|||||||
if p.tok.kind == .comma {
|
if p.tok.kind == .comma {
|
||||||
p.error_with_pos('const declaration do not support multiple assign yet', p.tok.pos())
|
p.error_with_pos('const declaration do not support multiple assign yet', p.tok.pos())
|
||||||
}
|
}
|
||||||
|
if p.tok.kind == .decl_assign {
|
||||||
|
p.error_with_pos('cannot use `:=` to declare a const, use `=` instead', p.tok.pos())
|
||||||
|
}
|
||||||
p.check(.assign)
|
p.check(.assign)
|
||||||
end_comments << p.eat_comments()
|
end_comments << p.eat_comments()
|
||||||
if p.tok.kind == .key_fn {
|
if p.tok.kind == .key_fn {
|
||||||
|
5
vlib/v/parser/tests/const_init_decl_assign_err.out
Normal file
5
vlib/v/parser/tests/const_init_decl_assign_err.out
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
vlib/v/parser/tests/const_init_decl_assign_err.vv:2:4: error: cannot use `:=` to declare a const, use `=` instead
|
||||||
|
1 | const (
|
||||||
|
2 | a := 43
|
||||||
|
| ~~
|
||||||
|
3 | )
|
3
vlib/v/parser/tests/const_init_decl_assign_err.vv
Normal file
3
vlib/v/parser/tests/const_init_decl_assign_err.vv
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
const (
|
||||||
|
a := 43
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user