checker: cleanup in match_expr() (#22407)

This commit is contained in:
yuyi 2024-10-04 15:11:17 +08:00 committed by GitHub
parent cafb69dee2
commit 286c44266d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
@ -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{