checker: add error for assigning `none` values (#13383)
parent
31df2c4f45
commit
d46ac40758
|
@ -47,6 +47,9 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
||||||
c.error('unexpected `mut` on right-hand side of assignment', right.mut_pos)
|
c.error('unexpected `mut` on right-hand side of assignment', right.mut_pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if right is ast.None {
|
||||||
|
c.error('you can not assign a `none` value to a variable', right.pos)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if node.left.len != right_len {
|
if node.left.len != right_len {
|
||||||
if right_first is ast.CallExpr {
|
if right_first is ast.CallExpr {
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
vlib/v/checker/tests/assing_none.vv:2:9: error: you can not assign a `none` value to a variable
|
||||||
|
1 | fn main() {
|
||||||
|
2 | val := none
|
||||||
|
| ~~~~
|
||||||
|
3 | println(val)
|
||||||
|
4 | }
|
|
@ -0,0 +1,4 @@
|
||||||
|
fn main() {
|
||||||
|
val := none
|
||||||
|
println(val)
|
||||||
|
}
|
Loading…
Reference in New Issue