Skip to content

Commit 3c48780

Browse files
authored
checker: fix missing check for a := [none] (fix #23457) (#23504)
1 parent e202641 commit 3c48780

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎vlib/v/checker/containers.v‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type {
174174
typ = c.check_expr_option_or_result_call(expr, c.expr(mut expr))
175175
c.expected_type = old_expected_type
176176
} else {
177+
// [none]
178+
if c.expected_type == ast.none_type && expr is ast.None {
179+
c.error('invalid expression `none`, it is not an array of Option type',
180+
expr.pos())
181+
continue
182+
}
177183
typ = c.check_expr_option_or_result_call(expr, c.expr(mut expr))
178184
}
179185
if expr is ast.CallExpr {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
vlib/v/checker/tests/array_none_element_err.vv:2:8: error: invalid expression `none`, it is not an array of Option type
2+
1 | fn main() {
3+
2 | a := [none]
4+
| ~~~~
5+
3 | println('${a}')
6+
4 | }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
a := [none]
3+
println('${a}')
4+
}

0 commit comments

Comments
 (0)