1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: apply the new array check only to len:, not cap: inits

This commit is contained in:
Alexander Medvednikov 2022-07-06 07:03:36 +03:00
parent fab5802deb
commit d3090de02e
2 changed files with 3 additions and 4 deletions

View File

@ -58,9 +58,8 @@ pub fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type {
}
// &int{} check
if node.elem_type.is_any_kind_of_pointer() && !c.inside_unsafe
&& (node.has_len || node.has_cap) {
c.warn('arrays of references need to be initialized right away (unless used inside `unsafe`)',
if node.elem_type.is_any_kind_of_pointer() && !c.inside_unsafe && node.has_len {
c.warn('arrays of references need to be initialized right away, therefore `len:` cannot be used (unless inside `unsafe`)',
node.pos)
}
return node.typ

View File

@ -1,4 +1,4 @@
vlib/v/checker/tests/ptr_array_init.vv:2:14: warning: arrays of references need to be initialized right away (unless used inside `unsafe`)
vlib/v/checker/tests/ptr_array_init.vv:2:14: warning: arrays of references need to be initialized right away, therefore `len:` cannot be used (unless inside `unsafe`)
1 | fn main() {
2 | println(*[]&int{len: 1}[0])
| ~~~~~~~