1
0
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:
Swastik Baranwal 2023-04-21 22:03:23 +05:30 committed by GitHub
parent eb410bf283
commit 456968b07d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 0 deletions

View File

@ -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 {}

View 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')

View File

@ -0,0 +1,2 @@
mut a := []array{}
a.insert(4, '1')