checker: disallow `<-` (channel push) on right-hand side of assignment (fix #12309) (#12321)

pull/12314/head
Lucas Jenß 2021-10-27 16:53:50 +02:00 committed by GitHub
parent 159a9c3070
commit 43fbc68f1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 0 deletions

View File

@ -3711,6 +3711,12 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
right_len = 0
}
}
if right is ast.InfixExpr {
if right.op == .arrow {
c.error('cannot use `<-` on the right-hand side of an assignment, as it does not return any values',
right.pos)
}
}
}
if node.left.len != right_len {
if right_first is ast.CallExpr {

View File

@ -0,0 +1,4 @@
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
1 | ch := chan f64{}
2 | _ := ch <- 4.56
|

View File

@ -0,0 +1,2 @@
ch := chan f64{}
_ := ch <- 4.56