diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 02382cafd8..85ec29d593 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -1014,7 +1014,7 @@ fn (g mut Gen) match_expr(node ast.MatchExpr) { match fe { ast.Type { it_type := g.typ(it.typ) - g.writeln('$it_type* it = ($it_type*)tmp3.obj; // ST it') + g.writeln('$it_type* it = ($it_type*)${tmp}.obj; // ST it') } else { verror('match sum type') diff --git a/vlib/v/gen/tests/3.c b/vlib/v/gen/tests/3.c index 7f40895b2d..1b32538654 100644 --- a/vlib/v/gen/tests/3.c +++ b/vlib/v/gen/tests/3.c @@ -41,11 +41,11 @@ void println(string s) { void handle_expr(Expr e) { Expr tmp1 = e; if (tmp1.typ == _type_idx_IfExpr) { - IfExpr* it = (IfExpr*)tmp3.obj; // ST it + IfExpr* it = (IfExpr*)tmp1.obj; // ST it println(tos3("if")); } else if (tmp1.typ == _type_idx_IntegerLiteral) { - IntegerLiteral* it = (IntegerLiteral*)tmp3.obj; // ST it + IntegerLiteral* it = (IntegerLiteral*)tmp1.obj; // ST it println(tos3("integer")); } else { @@ -62,5 +62,7 @@ int main() { user.name = tos3("bob"); Option_int n = get_opt(); int a = /*opt*/(*(int*)n.data) + 3; + handle_expr((IfExpr){ +0}); return 0; } diff --git a/vlib/v/gen/tests/3.vv b/vlib/v/gen/tests/3.vv index c7fec00098..63092d63a6 100644 --- a/vlib/v/gen/tests/3.vv +++ b/vlib/v/gen/tests/3.vv @@ -46,4 +46,5 @@ fn main() { return } a := n + 3 + handle_expr(IfExpr{}) } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 7c10febc96..0a1c5b46a9 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1620,7 +1620,7 @@ fn (p mut Parser) match_expr() ast.MatchExpr { } p.scope.register_var(ast.Var{ name: 'it' - typ: typ + typ: table.type_to_ptr(typ) }) // TODO if p.tok.kind == .comma {