|
121 | 121 | is_fn_index_call bool |
122 | 122 | is_cc_msvc bool // g.pref.ccompiler == 'msvc' |
123 | 123 | is_option_auto_heap bool |
| 124 | + is_auto_deref_synthetic bool |
124 | 125 | vlines_path string // set to the proper path for generating #line directives |
125 | 126 | options_pos_forward int // insertion point to forward |
126 | 127 | options_forward []string // to forward |
@@ -7267,7 +7268,7 @@ fn (mut g Gen) expr(node_ ast.Expr) { |
7267 | 7268 | // For `*val` where val is a mut generic param with pointer type |
7268 | 7269 | // (e.g. `mut val T` where T=&int -> C: `int** val`), auto-deref needs |
7269 | 7270 | // an extra `*` so `*val` in V becomes `**val` in C. |
7270 | | - if node.op == .mul && node.right is ast.Ident { |
| 7271 | + if node.op == .mul && node.right is ast.Ident && !g.is_auto_deref_synthetic { |
7271 | 7272 | ident_right := node.right as ast.Ident |
7272 | 7273 | if ident_right.obj is ast.Var && ident_right.obj.is_auto_deref |
7273 | 7274 | && ident_right.obj.is_arg && ident_right.obj.generic_typ != 0 { |
@@ -11656,14 +11657,42 @@ fn (mut g Gen) return_stmt(node ast.Return) { |
11656 | 11657 | final_assignments += g.go_before_last_stmt() + '\t' |
11657 | 11658 | g.write2(line, '{0}') |
11658 | 11659 | } else { |
11659 | | - if expr.is_auto_deref_var() { |
11660 | | - g.write('*') |
| 11660 | + is_auto_deref := expr.is_auto_deref_var() |
| 11661 | + mut resolved_ret_type := ret_expr_types[i] |
| 11662 | + if g.cur_concrete_types.len > 0 { |
| 11663 | + if expr is ast.Ident { |
| 11664 | + resolved_type := g.resolved_scope_var_type_uncached(expr) |
| 11665 | + if resolved_type != 0 { |
| 11666 | + resolved_ret_type = resolved_type |
| 11667 | + if is_auto_deref { |
| 11668 | + resolved_ret_type = resolved_ret_type.deref() |
| 11669 | + } |
| 11670 | + } |
| 11671 | + } else { |
| 11672 | + resolved_type := g.resolved_expr_type(expr, resolved_ret_type) |
| 11673 | + if resolved_type != 0 && !g.type_has_unresolved_generic_parts(resolved_type) { |
| 11674 | + resolved_ret_type = resolved_type |
| 11675 | + } |
| 11676 | + } |
11661 | 11677 | } |
11662 | 11678 | if mr_info.types[i].has_flag(.option) { |
11663 | | - g.expr_with_opt(expr, ret_expr_types[i], mr_info.types[i]) |
| 11679 | + if is_auto_deref { |
| 11680 | + g.write('*') |
| 11681 | + } |
| 11682 | + g.expr_with_opt(expr, resolved_ret_type, mr_info.types[i]) |
11664 | 11683 | } else if g.table.sym(mr_info.types[i]).kind in [.sum_type, .interface] { |
11665 | | - g.expr_with_cast(expr, ret_expr_types[i], mr_info.types[i]) |
| 11684 | + if is_auto_deref { |
| 11685 | + g.is_auto_deref_synthetic = true |
| 11686 | + g.expr_with_cast(ast.PrefixExpr{ op: .mul, right: expr }, |
| 11687 | + resolved_ret_type, mr_info.types[i]) |
| 11688 | + g.is_auto_deref_synthetic = false |
| 11689 | + } else { |
| 11690 | + g.expr_with_cast(expr, resolved_ret_type, mr_info.types[i]) |
| 11691 | + } |
11666 | 11692 | } else { |
| 11693 | + if is_auto_deref { |
| 11694 | + g.write('*') |
| 11695 | + } |
11667 | 11696 | g.expr(expr) |
11668 | 11697 | } |
11669 | 11698 | } |
|
0 commit comments