Skip to content

Commit 43fbc68

Browse files
authored
checker: disallow <- (channel push) on right-hand side of assignment (fix #12309) (#12321)
1 parent 159a9c3 commit 43fbc68

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

vlib/v/checker/checker.v

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3711,6 +3711,12 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
37113711
right_len = 0
37123712
}
37133713
}
3714+
if right is ast.InfixExpr {
3715+
if right.op == .arrow {
3716+
c.error('cannot use `<-` on the right-hand side of an assignment, as it does not return any values',
3717+
right.pos)
3718+
}
3719+
}
37143720
}
37153721
if node.left.len != right_len {
37163722
if right_first is ast.CallExpr {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
vlib/v/checker/tests/assign_expr_channel_push.vv:2:9: error: cannot use `<-` on the right-hand side of an assignment, as it does not return any values
2+
1 | ch := chan f64{}
3+
2 | _ := ch <- 4.56
4+
|
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ch := chan f64{}
2+
_ := ch <- 4.56

0 commit comments

Comments
 (0)