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:
parent
fab5802deb
commit
d3090de02e
@ -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
|
||||
|
@ -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])
|
||||
| ~~~~~~~
|
||||
|
Loading…
Reference in New Issue
Block a user