@@ -2289,6 +2289,7 @@ fn (mut g Gen) keep_alive_call_postgen(node ast.CallExpr, tmp_cnt_save int) {
2289
2289
[inline ]
2290
2290
fn (mut g Gen) ref_or_deref_arg (arg ast.CallArg, expected_type ast.Type, lang ast.Language) {
2291
2291
arg_typ := g.unwrap_generic (arg.typ)
2292
+ arg_sym := g.table.sym (arg_typ)
2292
2293
exp_is_ptr := expected_type.is_ptr () || expected_type.idx () in ast.pointer_type_idxs
2293
2294
arg_is_ptr := arg_typ.is_ptr () || arg_typ.idx () in ast.pointer_type_idxs
2294
2295
if expected_type == 0 {
@@ -2300,7 +2301,6 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
2300
2301
g.write ('&/*mut*/' )
2301
2302
} else if exp_is_ptr && ! arg_is_ptr {
2302
2303
if arg.is_mut {
2303
- arg_sym := g.table.sym (arg_typ)
2304
2304
if exp_sym.kind == .array {
2305
2305
if (arg.expr is ast.Ident && (arg.expr as ast.Ident ).kind == .variable)
2306
2306
|| arg.expr is ast.SelectorExpr {
@@ -2353,6 +2353,19 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
2353
2353
g.write ('ADDR(${g.typ(atype)} /*qq*/, ' )
2354
2354
}
2355
2355
}
2356
+ } else if arg_sym.kind == .sum_type && exp_sym.kind == .sum_type {
2357
+ // Automatically passing sum types by reference if the argument expects it,
2358
+ // not only the argument is mutable.
2359
+ if arg.expr is ast.SelectorExpr {
2360
+ g.write ('&/*sum*/' )
2361
+ g.expr (arg.expr)
2362
+ return
2363
+ } else if arg.expr is ast.CastExpr {
2364
+ g.write ('ADDR(${g.typ(expected_deref_type)} /*sum*/, ' )
2365
+ g.expr_with_cast (arg.expr, arg_typ, expected_type)
2366
+ g.write (')' )
2367
+ return
2368
+ }
2356
2369
}
2357
2370
}
2358
2371
} else if arg_typ.has_flag (.shared_f) && ! expected_type.has_flag (.shared_f) {
0 commit comments