From 91378583cc97d3777c7fbffae99f591df4614a34 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 18 Mar 2020 12:34:27 +0100 Subject: [PATCH] cgen: another expected_type fix --- vlib/v/ast/ast.v | 1 + vlib/v/checker/checker.v | 6 +++--- vlib/v/gen/cgen.v | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 8d66a0779d..2680811569 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -355,6 +355,7 @@ mut: is_expr bool // returns a value return_type table.Type cond_type table.Type // type of `x` in `match x {` + // expected_type table.Type // for debugging only is_sum_type bool } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 196f503178..f5c64dcf53 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -582,6 +582,7 @@ fn (c mut Checker) stmts(stmts []ast.Stmt) { for stmt in stmts { c.stmt(stmt) } + c.expected_type = table.void_type } pub fn (c mut Checker) expr(node ast.Expr) table.Type { @@ -790,6 +791,7 @@ pub fn (c mut Checker) ident(ident mut ast.Ident) table.Type { pub fn (c mut Checker) match_expr(node mut ast.MatchExpr) table.Type { node.is_expr = c.expected_type != table.void_type + // node.expected_type = c.expected_type cond_type := c.expr(node.cond) if cond_type == 0 { c.error('match 0 cond type', node.pos) @@ -845,9 +847,7 @@ pub fn (c mut Checker) if_expr(node mut ast.IfExpr) table.Type { if table.type_idx(typ) != table.bool_type_idx { c.error('non-bool (`$typ_sym.name`) used as if condition', node.pos) } - for i, stmt in node.stmts { - c.stmt(stmt) - } + c.stmts(node.stmts) if node.else_stmts.len > 0 { c.stmts(node.else_stmts) } diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 667bc93b5a..6a406f3049 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -977,7 +977,7 @@ fn (g mut Gen) match_expr(node ast.MatchExpr) { is_expr := node.is_expr && node.return_type != table.void_type if is_expr { g.inside_ternary = true - // g.write('/* EM ret type=${g.typ(node.return_type)} */') + // g.write('/* EM ret type=${g.typ(node.return_type)} expected_type=${g.typ(node.expected_type)} */') } type_sym := g.table.get_type_symbol(node.cond_type) mut tmp := ''