diff --git a/vlib/v/checker/containers.v b/vlib/v/checker/containers.v index 1d1c81ee63..6add51676e 100644 --- a/vlib/v/checker/containers.v +++ b/vlib/v/checker/containers.v @@ -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 {} diff --git a/vlib/v/checker/tests/array_decl_type_err.out b/vlib/v/checker/tests/array_decl_type_err.out new file mode 100644 index 0000000000..1ba7ff1d2b --- /dev/null +++ b/vlib/v/checker/tests/array_decl_type_err.out @@ -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') diff --git a/vlib/v/checker/tests/array_decl_type_err.vv b/vlib/v/checker/tests/array_decl_type_err.vv new file mode 100644 index 0000000000..97827270a3 --- /dev/null +++ b/vlib/v/checker/tests/array_decl_type_err.vv @@ -0,0 +1,2 @@ +mut a := []array{} +a.insert(4, '1')