mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: allow aa := AA{}
, when AA
has an option field, that is a struct, that has a [required]
tag on its fields (#17516)
This commit is contained in:
parent
77b6bc1c1a
commit
65a627d72b
@ -648,7 +648,7 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini
|
||||
}
|
||||
}
|
||||
if !field.has_default_expr && field.name !in inited_fields && !field.typ.is_ptr()
|
||||
&& c.table.final_sym(field.typ).kind == .struct_ {
|
||||
&& !field.typ.has_flag(.option) && c.table.final_sym(field.typ).kind == .struct_ {
|
||||
mut zero_struct_init := ast.StructInit{
|
||||
pos: node.pos
|
||||
typ: field.typ
|
||||
|
@ -14,3 +14,17 @@ fn test_nested_option_struct_init() {
|
||||
assert d2.d.b != none
|
||||
assert d2.d.b? == 1
|
||||
}
|
||||
|
||||
struct AA {
|
||||
bb ?BB // defaults to none
|
||||
}
|
||||
|
||||
struct BB {
|
||||
x string [required]
|
||||
}
|
||||
|
||||
fn test_nested_option_struct_with_attr_init() {
|
||||
aa := AA{}
|
||||
println(aa)
|
||||
assert aa.bb == none
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user