Skip to content

Commit

Permalink
parser: disallow an empty chan type (#19167)
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 committed Aug 17, 2023
1 parent 4908ec5 commit c862394
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vlib/v/parser/parser.v
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions 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{}
| ~~~~~~
1 change: 1 addition & 0 deletions vlib/v/parser/tests/no_chan_type_provided_err.vv
@@ -0,0 +1 @@
_ = chan{}

0 comments on commit c862394

Please sign in to comment.