From f8461e2b3ccbe87635cface142e7d8347bf3820c Mon Sep 17 00:00:00 2001 From: yuyi Date: Wed, 29 Jun 2022 17:03:56 +0800 Subject: [PATCH] parser: check const declaration using multiple assign (#14886) --- vlib/v/parser/parser.v | 3 +++ vlib/v/parser/tests/const_decl_err.out | 7 +++++++ vlib/v/parser/tests/const_decl_err.vv | 12 ++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 vlib/v/parser/tests/const_decl_err.out create mode 100644 vlib/v/parser/tests/const_decl_err.vv diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index b4d8b4b165..26ec2e3f25 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -3364,6 +3364,9 @@ fn (mut p Parser) const_decl() ast.ConstDecl { pos) } full_name := p.prepend_mod(name) + if p.tok.kind == .comma { + p.error_with_pos('const declaration do not support multiple assign yet', 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_decl_err.out b/vlib/v/parser/tests/const_decl_err.out new file mode 100644 index 0000000000..bf9db23091 --- /dev/null +++ b/vlib/v/parser/tests/const_decl_err.out @@ -0,0 +1,7 @@ +vlib/v/parser/tests/const_decl_err.vv:6:3: error: const declaration do not support multiple assign yet + 4 | + 5 | const ( + 6 | a, b, c = foo() + | ^ + 7 | ) + 8 | diff --git a/vlib/v/parser/tests/const_decl_err.vv b/vlib/v/parser/tests/const_decl_err.vv new file mode 100644 index 0000000000..324d61b5ce --- /dev/null +++ b/vlib/v/parser/tests/const_decl_err.vv @@ -0,0 +1,12 @@ +fn foo() (int, int, int) { + return 1, 2, 3 +} + +const ( + a, b, c = foo() +) + + +fn main() { + println("$a $b $c") +}