mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check array init with a void type value (#13106)
This commit is contained in:
parent
86ba4517b1
commit
0ac450927c
@ -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 {
|
||||
|
7
vlib/v/checker/tests/array_init_with_void_value_err.out
Normal file
7
vlib/v/checker/tests/array_init_with_void_value_err.out
Normal 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 | }
|
8
vlib/v/checker/tests/array_init_with_void_value_err.vv
Normal file
8
vlib/v/checker/tests/array_init_with_void_value_err.vv
Normal file
@ -0,0 +1,8 @@
|
||||
module main
|
||||
|
||||
fn main() {
|
||||
a := [yo()]
|
||||
println(a)
|
||||
}
|
||||
|
||||
fn yo() {}
|
Loading…
Reference in New Issue
Block a user