1
0
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:
Swastik Baranwal 2022-12-07 01:14:33 +05:30 committed by GitHub
parent 921416d821
commit bb705c01d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 0 deletions

View File

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

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

View File

@ -0,0 +1,3 @@
const (
a := 43
)