mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix embedded structure initialization warnings (#18385)
This commit is contained in:
parent
dd1d5bca1b
commit
42db392e76
@ -586,6 +586,16 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini
|
|||||||
field.expr.pos)
|
field.expr.pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// all the fields of initialized embedded struct are ignored, they are considered initialized
|
||||||
|
sym := c.table.sym(field.typ)
|
||||||
|
if field.name.len > 0 && field.name[0].is_capital() && sym.kind == .struct_
|
||||||
|
&& sym.language == .v {
|
||||||
|
struct_fields := c.table.struct_fields(sym)
|
||||||
|
for struct_field in struct_fields {
|
||||||
|
inited_fields << struct_field.name
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Check uninitialized refs/sum types
|
// Check uninitialized refs/sum types
|
||||||
// The variable `fields` contains two parts, the first part is the same as info.fields,
|
// The variable `fields` contains two parts, the first part is the same as info.fields,
|
||||||
|
5
vlib/v/slow_tests/inout/struct_with_embed_field_init.out
Normal file
5
vlib/v/slow_tests/inout/struct_with_embed_field_init.out
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Outer{
|
||||||
|
Embedded: Embedded{
|
||||||
|
a: &nil
|
||||||
|
}
|
||||||
|
}
|
20
vlib/v/slow_tests/inout/struct_with_embed_field_init.vv
Normal file
20
vlib/v/slow_tests/inout/struct_with_embed_field_init.vv
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
struct Embedded {
|
||||||
|
a &int
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_embedded() Embedded {
|
||||||
|
return Embedded{
|
||||||
|
a: unsafe { nil }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Outer {
|
||||||
|
Embedded
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
o := Outer{
|
||||||
|
Embedded: new_embedded()
|
||||||
|
}
|
||||||
|
println(o)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user