checker: check array init with a void type value (#13106)

pull/13113/head
yuyi 2022-01-09 22:53:37 +08:00 committed by GitHub
parent 86ba4517b1
commit 0ac450927c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -85,6 +85,9 @@ pub fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type {
// }
for i, mut expr in node.exprs {
typ := c.check_expr_opt_call(expr, c.expr(expr))
if typ == ast.void_type {
c.error('invalid void array element type', expr.position())
}
node.expr_types << typ
// The first element's type
if expecting_interface_array {

View File

@ -0,0 +1,7 @@
vlib/v/checker/tests/array_init_with_void_value_err.vv:4:8: error: invalid void array element type
2 |
3 | fn main() {
4 | a := [yo()]
| ~~~~
5 | println(a)
6 | }

View File

@ -0,0 +1,8 @@
module main
fn main() {
a := [yo()]
println(a)
}
fn yo() {}