diff --git a/vlib/v/checker/containers.v b/vlib/v/checker/containers.v index ce88c2c3b0..f58214e894 100644 --- a/vlib/v/checker/containers.v +++ b/vlib/v/checker/containers.v @@ -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 diff --git a/vlib/v/checker/tests/ptr_array_init.out b/vlib/v/checker/tests/ptr_array_init.out index ada30a138b..47af51cd2e 100644 --- a/vlib/v/checker/tests/ptr_array_init.out +++ b/vlib/v/checker/tests/ptr_array_init.out @@ -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]) | ~~~~~~~