mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: disallow []array{}
(#17994)
This commit is contained in:
parent
eb410bf283
commit
456968b07d
@ -104,8 +104,14 @@ fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type {
|
||||
c.warn('arrays of references need to be initialized right away, therefore `len:` cannot be used (unless inside `unsafe`)',
|
||||
node.pos)
|
||||
}
|
||||
|
||||
if node.elem_type.idx() == ast.array_type && !c.is_builtin_mod {
|
||||
c.error('`array` is an internal type, it cannot be used directly. Use `[]int`, `[]Foo` etc',
|
||||
node.pos)
|
||||
}
|
||||
return node.typ
|
||||
}
|
||||
|
||||
if node.is_fixed {
|
||||
c.ensure_sumtype_array_has_default_value(node)
|
||||
c.ensure_type_exists(node.elem_type, node.elem_type_pos) or {}
|
||||
|
4
vlib/v/checker/tests/array_decl_type_err.out
Normal file
4
vlib/v/checker/tests/array_decl_type_err.out
Normal file
@ -0,0 +1,4 @@
|
||||
vlib/v/checker/tests/array_decl_type_err.vv:1:10: error: `array` is an internal type, it cannot be used directly. Use `[]int`, `[]Foo` etc
|
||||
1 | mut a := []array{}
|
||||
| ~~~~~~~~
|
||||
2 | a.insert(4, '1')
|
2
vlib/v/checker/tests/array_decl_type_err.vv
Normal file
2
vlib/v/checker/tests/array_decl_type_err.vv
Normal file
@ -0,0 +1,2 @@
|
||||
mut a := []array{}
|
||||
a.insert(4, '1')
|
Loading…
Reference in New Issue
Block a user