diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 9d1f274e36..495d82786e 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -6466,6 +6466,9 @@ fn (mut g Gen) as_cast(node ast.AsCast) { } } else if expr_type_sym.kind == .interface_ && sym.kind == .interface_ { g.write('I_${expr_type_sym.cname}_as_I_${sym.cname}(') + if node.expr_type.is_ptr() { + g.write('*') + } g.expr(node.expr) g.write(')') diff --git a/vlib/v/gen/c/infix_expr.v b/vlib/v/gen/c/infix_expr.v index f10b70f583..b015e392f2 100644 --- a/vlib/v/gen/c/infix_expr.v +++ b/vlib/v/gen/c/infix_expr.v @@ -448,6 +448,9 @@ fn (mut g Gen) gen_interface_is_op(node ast.InfixExpr) { return } g.write('I_${left_sym.cname}_is_I_${right_sym.cname}(') + if node.left_type.is_ptr() { + g.write('*') + } g.expr(node.left) g.write(')') } diff --git a/vlib/v/tests/interface_runtime_conversions_test.v b/vlib/v/tests/interface_runtime_conversions_test.v index d0d7294dec..78443451d4 100644 --- a/vlib/v/tests/interface_runtime_conversions_test.v +++ b/vlib/v/tests/interface_runtime_conversions_test.v @@ -21,6 +21,15 @@ fn draw(w Widget) { } } +fn draw_ref(w &Widget) { + if w is ResizableWidget { + rw := w as ResizableWidget + assert rw.resize(10, 20) == 200 + } else { + assert false + } +} + // implements Widget, but not ResizableWidget struct WidgetA { }