@@ -6624,19 +6624,30 @@ fn (mut g Gen) gen_or_block_stmts(cvar_name string, cast_typ string, stmts []ast
6624
6624
is_array_fixed = expr_stmt.expr is ast.ArrayInit
6625
6625
&& g.table.final_sym (return_type).kind == .array_fixed
6626
6626
if ! is_array_fixed {
6627
- g.write ('*(${cast_typ} *) ${cvar_name} .data = ' )
6627
+ if g.inside_return && ! g.inside_struct_init
6628
+ && expr_stmt.expr is ast.CallExpr
6629
+ && return_type.has_option_or_result () {
6630
+ g.write ('${cvar_name} = ' )
6631
+ } else {
6632
+ g.write ('*(${cast_typ} *) ${cvar_name} .data = ' )
6633
+ }
6628
6634
}
6629
6635
} else {
6630
6636
g.write ('${cvar_name} = ' )
6631
6637
}
6632
-
6633
6638
if is_array_fixed {
6634
6639
g.write ('memcpy(${cvar_name} .data, (${cast_typ} )' )
6635
6640
}
6636
- old_inside_opt_data := g.inside_opt_data
6637
- g.inside_opt_data = true
6638
- g.expr_with_cast (expr_stmt.expr, expr_stmt.typ, return_type.clear_option_and_result ())
6639
- g.inside_opt_data = old_inside_opt_data
6641
+ // return expr or { fn_returns_option() }
6642
+ if is_option && g.inside_return && expr_stmt.expr is ast.CallExpr
6643
+ && return_type.has_option_or_result () {
6644
+ g.expr_with_cast (expr_stmt.expr, expr_stmt.typ, return_type)
6645
+ } else {
6646
+ old_inside_opt_data := g.inside_opt_data
6647
+ g.inside_opt_data = true
6648
+ g.expr_with_cast (expr_stmt.expr, expr_stmt.typ, return_type.clear_option_and_result ())
6649
+ g.inside_opt_data = old_inside_opt_data
6650
+ }
6640
6651
if is_array_fixed {
6641
6652
g.write (', sizeof(${cast_typ} ))' )
6642
6653
}
0 commit comments