mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: add error for assigning none
values (#13383)
This commit is contained in:
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)
|
||||
}
|
||||
}
|
||||
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 {
|
||||
|
6
vlib/v/checker/tests/assing_none.out
Normal file
6
vlib/v/checker/tests/assing_none.out
Normal 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 | }
|
4
vlib/v/checker/tests/assing_none.vv
Normal file
4
vlib/v/checker/tests/assing_none.vv
Normal file
@ -0,0 +1,4 @@
|
||||
fn main() {
|
||||
val := none
|
||||
println(val)
|
||||
}
|
Loading…
Reference in New Issue
Block a user