cgen: another expected_type fix
parent
af289da844
commit
91378583cc
|
@ -355,6 +355,7 @@ mut:
|
||||||
is_expr bool // returns a value
|
is_expr bool // returns a value
|
||||||
return_type table.Type
|
return_type table.Type
|
||||||
cond_type table.Type // type of `x` in `match x {`
|
cond_type table.Type // type of `x` in `match x {`
|
||||||
|
// expected_type table.Type // for debugging only
|
||||||
is_sum_type bool
|
is_sum_type bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -582,6 +582,7 @@ fn (c mut Checker) stmts(stmts []ast.Stmt) {
|
||||||
for stmt in stmts {
|
for stmt in stmts {
|
||||||
c.stmt(stmt)
|
c.stmt(stmt)
|
||||||
}
|
}
|
||||||
|
c.expected_type = table.void_type
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (c mut Checker) expr(node ast.Expr) table.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 {
|
pub fn (c mut Checker) match_expr(node mut ast.MatchExpr) table.Type {
|
||||||
node.is_expr = c.expected_type != table.void_type
|
node.is_expr = c.expected_type != table.void_type
|
||||||
|
// node.expected_type = c.expected_type
|
||||||
cond_type := c.expr(node.cond)
|
cond_type := c.expr(node.cond)
|
||||||
if cond_type == 0 {
|
if cond_type == 0 {
|
||||||
c.error('match 0 cond type', node.pos)
|
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 {
|
if table.type_idx(typ) != table.bool_type_idx {
|
||||||
c.error('non-bool (`$typ_sym.name`) used as if condition', node.pos)
|
c.error('non-bool (`$typ_sym.name`) used as if condition', node.pos)
|
||||||
}
|
}
|
||||||
for i, stmt in node.stmts {
|
c.stmts(node.stmts)
|
||||||
c.stmt(stmt)
|
|
||||||
}
|
|
||||||
if node.else_stmts.len > 0 {
|
if node.else_stmts.len > 0 {
|
||||||
c.stmts(node.else_stmts)
|
c.stmts(node.else_stmts)
|
||||||
}
|
}
|
||||||
|
|
|
@ -977,7 +977,7 @@ fn (g mut Gen) match_expr(node ast.MatchExpr) {
|
||||||
is_expr := node.is_expr && node.return_type != table.void_type
|
is_expr := node.is_expr && node.return_type != table.void_type
|
||||||
if is_expr {
|
if is_expr {
|
||||||
g.inside_ternary = true
|
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)
|
type_sym := g.table.get_type_symbol(node.cond_type)
|
||||||
mut tmp := ''
|
mut tmp := ''
|
||||||
|
|
Loading…
Reference in New Issue