mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
@@ -522,6 +522,12 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
|
|||||||
if sym.kind == .struct_ && !(sym.info as ast.Struct).is_typedef {
|
if sym.kind == .struct_ && !(sym.info as ast.Struct).is_typedef {
|
||||||
c.check_ref_fields_initialized(sym, mut checked_structs, '${type_sym.name}.$field.name',
|
c.check_ref_fields_initialized(sym, mut checked_structs, '${type_sym.name}.$field.name',
|
||||||
node)
|
node)
|
||||||
|
} else if sym.kind == .alias {
|
||||||
|
parent_sym := c.table.sym((sym.info as ast.Alias).parent_type)
|
||||||
|
if parent_sym.kind == .struct_ {
|
||||||
|
c.check_ref_fields_initialized(parent_sym, mut checked_structs,
|
||||||
|
'${type_sym.name}.$field.name', node)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Do not allow empty uninitialized interfaces
|
// Do not allow empty uninitialized interfaces
|
||||||
mut has_noinit := false
|
mut has_noinit := false
|
||||||
@@ -608,6 +614,13 @@ fn (mut c Checker) check_ref_fields_initialized(struct_sym &ast.TypeSymbol, mut
|
|||||||
checked_structs << field.typ
|
checked_structs << field.typ
|
||||||
c.check_ref_fields_initialized(sym, mut checked_structs, '${linked_name}.$field.name',
|
c.check_ref_fields_initialized(sym, mut checked_structs, '${linked_name}.$field.name',
|
||||||
node)
|
node)
|
||||||
|
} else if sym.kind == .alias {
|
||||||
|
parent_sym := c.table.sym((sym.info as ast.Alias).parent_type)
|
||||||
|
if parent_sym.kind == .struct_ {
|
||||||
|
checked_structs << field.typ
|
||||||
|
c.check_ref_fields_initialized(parent_sym, mut checked_structs, '${linked_name}.$field.name',
|
||||||
|
node)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv:22:7: warning: reference field `Outer.c.b` must be initialized
|
vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv:25:7: warning: reference field `Outer.c1.b` must be initialized
|
||||||
20 |
|
23 |
|
||||||
21 | fn main() {
|
24 | fn main() {
|
||||||
22 | _ := Outer{}
|
25 | _ := Outer{}
|
||||||
| ~~~~~~~
|
| ~~~~~~~
|
||||||
23 | _ := Struct{}
|
26 | _ := Struct{}
|
||||||
24 | }
|
27 | }
|
||||||
vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv:23:7: warning: reference field `Struct.ref2` must be initialized
|
vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv:25:7: warning: reference field `Outer.c2.b` must be initialized
|
||||||
21 | fn main() {
|
23 |
|
||||||
22 | _ := Outer{}
|
24 | fn main() {
|
||||||
23 | _ := Struct{}
|
25 | _ := Outer{}
|
||||||
|
| ~~~~~~~
|
||||||
|
26 | _ := Struct{}
|
||||||
|
27 | }
|
||||||
|
vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv:26:7: warning: reference field `Struct.ref2` must be initialized
|
||||||
|
24 | fn main() {
|
||||||
|
25 | _ := Outer{}
|
||||||
|
26 | _ := Struct{}
|
||||||
| ~~~~~~~~
|
| ~~~~~~~~
|
||||||
24 | }
|
27 | }
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ struct ContainsRef {
|
|||||||
b &int
|
b &int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TypeForContainsRef = ContainsRef
|
||||||
|
|
||||||
struct Outer {
|
struct Outer {
|
||||||
c ContainsRef
|
c1 ContainsRef
|
||||||
|
c2 TypeForContainsRef
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Ref {}
|
struct Ref {}
|
||||||
|
|||||||
Reference in New Issue
Block a user