Skip to content

Commit c862394

Browse files
authored
parser: disallow an empty chan type (#19167)
1 parent 4908ec5 commit c862394

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

vlib/v/parser/parser.v

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,6 +2537,10 @@ fn (mut p Parser) name_expr() ast.Expr {
25372537
last_pos = p.tok.pos()
25382538
p.check(.rcbr)
25392539
}
2540+
if chan_type == ast.chan_type {
2541+
p.error_with_pos('`chan` has no type specified. Use `chan Type{}` instead of `chan{}`',
2542+
first_pos.extend(last_pos))
2543+
}
25402544
return ast.ChanInit{
25412545
pos: first_pos.extend(last_pos)
25422546
elem_type_pos: elem_type_pos
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vlib/v/parser/tests/no_chan_type_provided_err.vv:1:5: error: `chan` has no type specified. Use `chan Type{}` instead of `chan{}`
2+
1 | _ = chan{}
3+
| ~~~~~~
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_ = chan{}

0 commit comments

Comments
 (0)