Skip to content

Commit

Permalink
checker: cleanup in match_expr()
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Oct 4, 2024
1 parent 5b1581d commit cb3a9f7
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions vlib/v/checker/match.v
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
}
stmt.typ = expr_type
if first_iteration {
if node.expected_type.has_flag(.option) || node.expected_type.has_flag(.result)
if node.expected_type.has_option_or_result()
|| c.table.type_kind(node.expected_type) in [.sum_type, .multi_return] {
c.check_match_branch_last_stmt(stmt, node.expected_type, expr_type)
ret_type = node.expected_type
Expand All @@ -100,8 +100,7 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
}
} else {
if ret_type.idx() != expr_type.idx() {
if (node.expected_type.has_flag(.option)
|| node.expected_type.has_flag(.result))
if node.expected_type.has_option_or_result()
&& c.table.sym(stmt.typ).kind == .struct_
&& c.type_implements(stmt.typ, ast.error_type, node.pos) {
stmt.expr = ast.CastExpr{
Expand Down

0 comments on commit cb3a9f7

Please sign in to comment.