1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: clean and improve need_tmp_var_in_match() (#16451)

This commit is contained in:
yuyi 2022-11-17 15:08:45 +08:00 committed by GitHub
parent 37700502f5
commit cb9e945aa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,18 +7,14 @@ import v.ast
fn (mut g Gen) need_tmp_var_in_match(node ast.MatchExpr) bool {
if node.is_expr && node.return_type != ast.void_type && node.return_type != 0 {
cond_sym := g.table.final_sym(node.cond_type)
sym := g.table.sym(node.return_type)
if g.table.type_kind(node.return_type) == .sum_type {
if g.table.sym(node.return_type).kind in [.sum_type, .multi_return]
|| node.return_type.has_flag(.optional) || node.return_type.has_flag(.result) {
return true
}
if node.return_type.has_flag(.optional) || node.return_type.has_flag(.result) {
if g.table.final_sym(node.cond_type).kind == .enum_ && node.branches.len > 5 {
return true
}
if sym.kind == .multi_return {
return false
}
if cond_sym.kind == .enum_ && node.branches.len > 5 {
if g.need_tmp_var_in_expr(node.cond) {
return true
}
for branch in node.branches {