diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 68a6dc3b86..2a04780429 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -2296,13 +2296,13 @@ fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type_raw ast.Type, expected_typ g.writeln('}, sizeof($shared_styp))') return } - if got_is_ptr && !expected_is_ptr && neither_void - && exp_sym.kind !in [.interface_, .placeholder] && expr !is ast.InfixExpr { + if got_is_ptr && !expected_is_ptr && neither_void && exp_sym.kind != .placeholder + && expr !is ast.InfixExpr { got_deref_type := got_type.deref() deref_sym := g.table.get_type_symbol(got_deref_type) deref_will_match := expected_type in [got_type, got_deref_type, deref_sym.parent_idx] got_is_opt := got_type.has_flag(.optional) - if deref_will_match || got_is_opt { + if deref_will_match || got_is_opt || expr.is_auto_deref_var() { g.write('*') } } diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index e81189bfcf..aa7bf401c0 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -1306,10 +1306,6 @@ fn (mut g Gen) call_args(node ast.CallExpr) { g.write('/*af arg*/' + name) } } else { - if node.concrete_types.len > 0 && arg.expr.is_auto_deref_var() && !arg.is_mut - && !expected_types[i].is_ptr() { - g.write('*') - } g.ref_or_deref_arg(arg, expected_types[i], node.language) } } else { diff --git a/vlib/v/gen/c/infix_expr.v b/vlib/v/gen/c/infix_expr.v index 89f8c75bfa..28dd848677 100644 --- a/vlib/v/gen/c/infix_expr.v +++ b/vlib/v/gen/c/infix_expr.v @@ -580,9 +580,6 @@ fn (mut g Gen) infix_expr_left_shift_op(node ast.InfixExpr) { if needs_clone { g.write('string_clone(') } - if right.unaliased_sym.kind == .interface_ && node.right.is_auto_deref_var() { - g.write('*') - } g.expr_with_cast(node.right, node.right_type, array_info.elem_type) if needs_clone { g.write(')') diff --git a/vlib/v/tests/fn_mut_args_test.v b/vlib/v/tests/fn_mut_args_test.v index 41e0a29546..e0f014853e 100644 --- a/vlib/v/tests/fn_mut_args_test.v +++ b/vlib/v/tests/fn_mut_args_test.v @@ -67,3 +67,23 @@ fn test_fn_mut_args_of_interface() { println(x.children[0].data) assert x.children[0].data == 123 } + +struct LinuxFile { +} + +interface File { +} + +fn b(parent File) { + println(parent) + assert '$parent' == 'File(LinuxFile{})' +} + +fn a(mut parent File) { + b(parent) +} + +fn test_fn_mut_args_of_interface2() { + mut file := LinuxFile{} + a(mut file) +}