diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index b286228f49..a9340bd0e0 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -5302,6 +5302,12 @@ fn (mut g Gen) cast_expr(node ast.CastExpr) { g.expr_with_opt(node.expr, expr_type, sym.info.parent_type) } else { g.write('(${cast_label}(') + if node.expr is ast.Ident { + if !node.typ.is_ptr() && node.expr_type.is_ptr() && node.expr.obj is ast.Var + && node.expr.obj.smartcasts.len > 0 { + g.write('*'.repeat(node.expr_type.nr_muls())) + } + } if sym.kind == .alias && g.table.final_sym(node.typ).kind == .string { ptr_cnt := node.typ.nr_muls() - expr_type.nr_muls() if ptr_cnt > 0 { diff --git a/vlib/v/tests/casts/cast_interface_value_in_match_test.v b/vlib/v/tests/casts/cast_interface_value_in_match_test.v new file mode 100644 index 0000000000..bf5abe82f4 --- /dev/null +++ b/vlib/v/tests/casts/cast_interface_value_in_match_test.v @@ -0,0 +1,24 @@ +interface Number2 {} + +fn t(v Number2) { + match v { + int, i32, isize, i64 { + x := isize(v) + println(x) + assert x == 42 + } + else {} + } + match v { + int { + x := isize(v) + println(x) + assert x == 42 + } + else {} + } +} + +fn test_cast_interface_value_in_match() { + t(int(42)) +}