diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 18891ac5ee..97ec3cd7eb 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -3555,6 +3555,9 @@ fn (mut p Parser) const_decl() ast.ConstDecl { if p.tok.kind == .comma { 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) end_comments << p.eat_comments() if p.tok.kind == .key_fn { diff --git a/vlib/v/parser/tests/const_init_decl_assign_err.out b/vlib/v/parser/tests/const_init_decl_assign_err.out new file mode 100644 index 0000000000..9099e5f7f4 --- /dev/null +++ b/vlib/v/parser/tests/const_init_decl_assign_err.out @@ -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 | ) diff --git a/vlib/v/parser/tests/const_init_decl_assign_err.vv b/vlib/v/parser/tests/const_init_decl_assign_err.vv new file mode 100644 index 0000000000..9b9cafba4a --- /dev/null +++ b/vlib/v/parser/tests/const_init_decl_assign_err.vv @@ -0,0 +1,3 @@ +const ( + a := 43 +)