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