Skip to content

Commit

Permalink
checker: check untyped nil in assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Jul 19, 2022
1 parent 1aeca11 commit fd47385
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vlib/v/checker/assign.v
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/checker/tests/nil.out
@@ -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 | }
6 changes: 6 additions & 0 deletions vlib/v/checker/tests/nil.vv
@@ -0,0 +1,6 @@
fn main() {
unsafe {
value := nil
println(value)
}
}

0 comments on commit fd47385

Please sign in to comment.