@@ -31,42 +31,91 @@ fn (mut g Gen) need_tmp_var_in_expr(expr ast.Expr) bool {
31
31
if is_noreturn_callexpr (expr) {
32
32
return true
33
33
}
34
- if expr is ast.MatchExpr {
35
- return true
36
- }
37
- if expr is ast.CallExpr {
38
- if expr.is_method {
39
- left_sym := g.table.sym (expr.receiver_type)
40
- if left_sym.kind in [.array, .array_fixed, .map ] {
34
+ match expr {
35
+ ast.IfExpr {
36
+ if g.need_tmp_var_in_if (expr) {
41
37
return true
42
38
}
43
39
}
44
- if expr.or_block.kind != .absent {
40
+ ast.MatchExpr {
45
41
return true
46
42
}
47
- }
48
- if expr is ast.CastExpr {
49
- return g.need_tmp_var_in_expr (expr.expr)
50
- }
51
- if expr is ast.ParExpr {
52
- return g.need_tmp_var_in_expr (expr.expr)
53
- }
54
- if expr is ast.ConcatExpr {
55
- for val in expr.vals {
56
- if val is ast.CallExpr {
57
- if val.return_type.has_flag (.optional) {
43
+ ast.CallExpr {
44
+ if expr.is_method {
45
+ left_sym := g.table.sym (expr.receiver_type)
46
+ if left_sym.kind in [.array, .array_fixed, .map ] {
58
47
return true
59
48
}
60
49
}
50
+ if expr.or_block.kind != .absent {
51
+ return true
52
+ }
61
53
}
62
- }
63
- if expr is ast.IndexExpr {
64
- if expr.or_expr.kind != .absent {
65
- return true
54
+ ast.CastExpr {
55
+ return g.need_tmp_var_in_expr (expr.expr)
66
56
}
67
- if g.need_tmp_var_in_expr (expr.index) {
68
- return true
57
+ ast.ParExpr {
58
+ return g.need_tmp_var_in_expr (expr.expr)
59
+ }
60
+ ast.ConcatExpr {
61
+ for val in expr.vals {
62
+ if val is ast.CallExpr {
63
+ if val.return_type.has_flag (.optional) {
64
+ return true
65
+ }
66
+ }
67
+ }
68
+ }
69
+ ast.IndexExpr {
70
+ if expr.or_expr.kind != .absent {
71
+ return true
72
+ }
73
+ if g.need_tmp_var_in_expr (expr.index) {
74
+ return true
75
+ }
76
+ }
77
+ ast.ArrayInit {
78
+ if g.need_tmp_var_in_expr (expr.len_expr) {
79
+ return true
80
+ }
81
+ if g.need_tmp_var_in_expr (expr.cap_expr) {
82
+ return true
83
+ }
84
+ if g.need_tmp_var_in_expr (expr.default_expr) {
85
+ return true
86
+ }
87
+ for elem_expr in expr.exprs {
88
+ if g.need_tmp_var_in_expr (elem_expr) {
89
+ return true
90
+ }
91
+ }
92
+ }
93
+ ast.MapInit {
94
+ for key in expr.keys {
95
+ if g.need_tmp_var_in_expr (key) {
96
+ return true
97
+ }
98
+ }
99
+ for val in expr.vals {
100
+ if g.need_tmp_var_in_expr (val) {
101
+ return true
102
+ }
103
+ }
104
+ }
105
+ ast.StructInit {
106
+ if g.need_tmp_var_in_expr (expr.update_expr) {
107
+ return true
108
+ }
109
+ for field in expr.fields {
110
+ if g.need_tmp_var_in_expr (field.expr) {
111
+ return true
112
+ }
113
+ }
114
+ }
115
+ ast.SelectorExpr {
116
+ return g.need_tmp_var_in_expr (expr.expr)
69
117
}
118
+ else {}
70
119
}
71
120
return false
72
121
}
0 commit comments