mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: minor cleanup in match_expr() (#13753)
This commit is contained in:
parent
33167960ed
commit
315e07abf6
@ -66,8 +66,7 @@ pub fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
|
|||||||
// If the last statement is an expression, return its type
|
// If the last statement is an expression, return its type
|
||||||
if branch.stmts.len > 0 {
|
if branch.stmts.len > 0 {
|
||||||
mut stmt := branch.stmts[branch.stmts.len - 1]
|
mut stmt := branch.stmts[branch.stmts.len - 1]
|
||||||
match mut stmt {
|
if mut stmt is ast.ExprStmt {
|
||||||
ast.ExprStmt {
|
|
||||||
if node.is_expr {
|
if node.is_expr {
|
||||||
c.expected_type = node.expected_type
|
c.expected_type = node.expected_type
|
||||||
}
|
}
|
||||||
@ -81,8 +80,7 @@ pub fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
|
|||||||
}
|
}
|
||||||
stmt.typ = expr_type
|
stmt.typ = expr_type
|
||||||
} else if node.is_expr && ret_type.idx() != expr_type.idx() {
|
} else if node.is_expr && ret_type.idx() != expr_type.idx() {
|
||||||
if !c.check_types(ret_type, expr_type)
|
if !c.check_types(ret_type, expr_type) && !c.check_types(expr_type, ret_type) {
|
||||||
&& !c.check_types(expr_type, ret_type) {
|
|
||||||
ret_sym := c.table.sym(ret_type)
|
ret_sym := c.table.sym(ret_type)
|
||||||
is_noreturn := is_noreturn_callexpr(stmt.expr)
|
is_noreturn := is_noreturn_callexpr(stmt.expr)
|
||||||
if !(node.is_expr && ret_sym.kind == .sum_type
|
if !(node.is_expr && ret_sym.kind == .sum_type
|
||||||
@ -94,15 +92,13 @@ pub fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if node.is_expr && ret_type != ast.void_type {
|
if node.is_expr && ret_type != ast.void_type {
|
||||||
c.error('`match` expression requires an expression as the last statement of every branch',
|
c.error('`match` expression requires an expression as the last statement of every branch',
|
||||||
stmt.pos)
|
stmt.pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
first_iteration = false
|
first_iteration = false
|
||||||
if has_return := c.has_return(branch.stmts) {
|
if has_return := c.has_return(branch.stmts) {
|
||||||
if has_return {
|
if has_return {
|
||||||
@ -122,10 +118,6 @@ pub fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
|
|||||||
c.returns = false
|
c.returns = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if ret_type != ast.void_type {
|
|
||||||
// node.is_expr = c.expected_type != ast.void_type
|
|
||||||
// node.expected_type = c.expected_type
|
|
||||||
// }
|
|
||||||
node.return_type = ret_type
|
node.return_type = ret_type
|
||||||
cond_var := c.get_base_name(&node.cond)
|
cond_var := c.get_base_name(&node.cond)
|
||||||
if cond_var != '' {
|
if cond_var != '' {
|
||||||
|
Loading…
Reference in New Issue
Block a user