@@ -742,21 +742,21 @@ fn (mut g Gen) struct_init_field(sfield ast.StructInitField, language ast.Langua
742742 g.fixed_array_var_init (tmp_var, false , field_unwrap_sym.info.elem_type,
743743 field_unwrap_sym.info.size)
744744 } else {
745- g.struct_init_field_default (field_unwrap_typ, sfield)
745+ g.struct_init_field_default (field_unwrap_typ, sfield, field_unwrap_sym )
746746 }
747747 }
748748 else {
749- g.struct_init_field_default (field_unwrap_typ, sfield)
749+ g.struct_init_field_default (field_unwrap_typ, sfield, field_unwrap_sym )
750750 }
751751 }
752752 } else {
753- g.struct_init_field_default (field_unwrap_typ, sfield)
753+ g.struct_init_field_default (field_unwrap_typ, sfield, field_unwrap_sym )
754754 }
755755 g.inside_cast_in_heap = inside_cast_in_heap // restore value for further struct inits
756756 }
757757}
758758
759- fn (mut g Gen) struct_init_field_default (field_unwrap_typ ast.Type, sfield & ast.StructInitField) {
759+ fn (mut g Gen) struct_init_field_default (field_unwrap_typ ast.Type, sfield & ast.StructInitField, field_unwrap_sym ast.TypeSymbol ) {
760760 if field_unwrap_typ != ast.voidptr_type && field_unwrap_typ != ast.nil_type
761761 && (sfield.expected_type.is_ptr () && ! sfield.expected_type.has_flag (.shared_f))
762762 && ! sfield.expected_type.has_flag (.option) && ! field_unwrap_typ.is_any_kind_of_pointer ()
@@ -769,6 +769,9 @@ fn (mut g Gen) struct_init_field_default(field_unwrap_typ ast.Type, sfield &ast.
769769 g.expr_with_opt (sfield.expr, field_unwrap_typ, sfield.expected_type)
770770 } else if sfield.expr is ast.LambdaExpr && sfield.expected_type.has_flag (.option) {
771771 g.expr_opt_with_cast (sfield.expr, field_unwrap_typ, sfield.expected_type)
772+ } else if field_unwrap_sym.kind == .function && sfield.expected_type.has_flag (.option) {
773+ tmp_out_var := g.new_tmp_var ()
774+ g.expr_with_tmp_var (sfield.expr, field_unwrap_typ, sfield.expected_type, tmp_out_var)
772775 } else {
773776 g.left_is_opt = true
774777 g.expr_with_cast (sfield.expr, field_unwrap_typ, sfield.expected_type)
0 commit comments