From 66adf7a6b928583a7dbd43db975b4cbd8aa436a5 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Mon, 16 Mar 2020 05:02:41 +0100 Subject: [PATCH] cgen: minor sum type fix --- vlib/v/gen/cgen.v | 2 +- vlib/v/gen/tests/3.c | 6 ++++-- vlib/v/gen/tests/3.vv | 1 + vlib/v/parser/parser.v | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) 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 {