1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: check untyped nil in assignment

This commit is contained in:
Alexander Medvednikov 2022-07-19 13:31:10 +03:00
parent 1aeca113d3
commit fd47385ff2
3 changed files with 16 additions and 0 deletions

View File

@ -220,6 +220,9 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
c.error('invalid use of reserved type `$left.name` as a variable name',
left.pos)
}
if right is ast.Nil {
c.error('use of untyped nil in assignment', right.pos())
}
}
mut ident_var_info := left.info as ast.IdentVar
if ident_var_info.share == .shared_t {

View File

@ -0,0 +1,7 @@
vlib/v/checker/tests/nil.vv:3:18: error: use of untyped nil in assignment
1 | fn main() {
2 | unsafe {
3 | value := nil
| ~~~
4 | println(value)
5 | }

View File

@ -0,0 +1,6 @@
fn main() {
unsafe {
value := nil
println(value)
}
}