mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: disallow all array
usage outside of builtin (#18222)
This commit is contained in:
parent
abcbba1e81
commit
4b22ea7803
@ -103,11 +103,6 @@ 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`)',
|
c.warn('arrays of references need to be initialized right away, therefore `len:` cannot be used (unless inside `unsafe`)',
|
||||||
node.pos)
|
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
|
return node.typ
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
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')
|
|
@ -489,6 +489,11 @@ pub fn (mut p Parser) parse_type() ast.Type {
|
|||||||
if is_atomic {
|
if is_atomic {
|
||||||
typ = typ.set_flag(.atomic_f)
|
typ = typ.set_flag(.atomic_f)
|
||||||
}
|
}
|
||||||
|
if typ.idx() == ast.array_type && !p.builtin_mod && p.mod !in ['os', 'strconv', 'sync']
|
||||||
|
&& !p.inside_unsafe {
|
||||||
|
p.error_with_pos('`array` is an internal type, it cannot be used directly. Use `[]int`, `[]Foo` etc',
|
||||||
|
pos)
|
||||||
|
}
|
||||||
if nr_muls > 0 {
|
if nr_muls > 0 {
|
||||||
typ = typ.set_nr_muls(nr_muls)
|
typ = typ.set_nr_muls(nr_muls)
|
||||||
if is_array && nr_amps > 0 {
|
if is_array && nr_amps > 0 {
|
||||||
|
3
vlib/v/parser/tests/array_decl_type_alias_err.out
Normal file
3
vlib/v/parser/tests/array_decl_type_alias_err.out
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
vlib/v/parser/tests/array_decl_type_alias_err.vv:1:12: error: `array` is an internal type, it cannot be used directly. Use `[]int`, `[]Foo` etc
|
||||||
|
1 | type Arr = array
|
||||||
|
| ~~~~~
|
1
vlib/v/parser/tests/array_decl_type_alias_err.vv
Normal file
1
vlib/v/parser/tests/array_decl_type_alias_err.vv
Normal file
@ -0,0 +1 @@
|
|||||||
|
type Arr = array
|
4
vlib/v/parser/tests/array_decl_type_err.out
Normal file
4
vlib/v/parser/tests/array_decl_type_err.out
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
vlib/v/parser/tests/array_decl_type_err.vv:1:12: error: `array` is an internal type, it cannot be used directly. Use `[]int`, `[]Foo` etc
|
||||||
|
1 | mut a := []array{}
|
||||||
|
| ~~~~~
|
||||||
|
2 | a.insert(4, '1')
|
7
vlib/v/parser/tests/array_decl_type_struct_field_err.out
Normal file
7
vlib/v/parser/tests/array_decl_type_struct_field_err.out
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
vlib/v/parser/tests/array_decl_type_struct_field_err.vv:6:20: error: `array` is an internal type, it cannot be used directly. Use `[]int`, `[]Foo` etc
|
||||||
|
4 | max_size string
|
||||||
|
5 | filter_until_hour int = 240 // 10 days
|
||||||
|
6 | prune_list array = ['all']
|
||||||
|
| ~~~~~
|
||||||
|
7 | time_interval int = 300 // 5 min
|
||||||
|
8 | }
|
8
vlib/v/parser/tests/array_decl_type_struct_field_err.vv
Normal file
8
vlib/v/parser/tests/array_decl_type_struct_field_err.vv
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
struct Config {
|
||||||
|
mut:
|
||||||
|
max_size string
|
||||||
|
filter_until_hour int = 240 // 10 days
|
||||||
|
prune_list array = ['all']
|
||||||
|
time_interval int = 300 // 5 min
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user