checker: add error for assigning `none` values (#13383)

pull/13389/head
Vincenzo Palazzo 2022-02-06 15:08:23 +01:00 committed by GitHub
parent 31df2c4f45
commit d46ac40758
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View File

@ -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)
}
}
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 right_first is ast.CallExpr {

View File

@ -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 | }

View File

@ -0,0 +1,4 @@
fn main() {
val := none
println(val)
}