From c8623943584a34090eb22bb88886b118ba21df8b Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Fri, 18 Aug 2023 01:41:02 +0530 Subject: [PATCH] parser: disallow an empty `chan` type (#19167) --- vlib/v/parser/parser.v | 4 ++++ vlib/v/parser/tests/no_chan_type_provided_err.out | 3 +++ vlib/v/parser/tests/no_chan_type_provided_err.vv | 1 + 3 files changed, 8 insertions(+) create mode 100644 vlib/v/parser/tests/no_chan_type_provided_err.out create mode 100644 vlib/v/parser/tests/no_chan_type_provided_err.vv diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index f14cda6666ad47..5c432f0a3dcea4 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -2537,6 +2537,10 @@ fn (mut p Parser) name_expr() ast.Expr { last_pos = p.tok.pos() p.check(.rcbr) } + if chan_type == ast.chan_type { + p.error_with_pos('`chan` has no type specified. Use `chan Type{}` instead of `chan{}`', + first_pos.extend(last_pos)) + } return ast.ChanInit{ pos: first_pos.extend(last_pos) elem_type_pos: elem_type_pos diff --git a/vlib/v/parser/tests/no_chan_type_provided_err.out b/vlib/v/parser/tests/no_chan_type_provided_err.out new file mode 100644 index 00000000000000..2a5049319b6386 --- /dev/null +++ b/vlib/v/parser/tests/no_chan_type_provided_err.out @@ -0,0 +1,3 @@ +vlib/v/parser/tests/no_chan_type_provided_err.vv:1:5: error: `chan` has no type specified. Use `chan Type{}` instead of `chan{}` + 1 | _ = chan{} + | ~~~~~~ diff --git a/vlib/v/parser/tests/no_chan_type_provided_err.vv b/vlib/v/parser/tests/no_chan_type_provided_err.vv new file mode 100644 index 00000000000000..83bf66e7a00e8a --- /dev/null +++ b/vlib/v/parser/tests/no_chan_type_provided_err.vv @@ -0,0 +1 @@ +_ = chan{}