@@ -1097,7 +1097,6 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
1097
1097
if is_call {
1098
1098
g.expr (val)
1099
1099
} else {
1100
- g.gen_default_init_value (val)
1101
1100
g.write ('{$styp _ = ' )
1102
1101
g.expr (val)
1103
1102
g.writeln (';}' )
@@ -1106,7 +1105,13 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
1106
1105
right_sym := g.table.get_type_symbol (assign_stmt.right_types[i])
1107
1106
mut is_fixed_array_init := false
1108
1107
mut has_val := false
1109
- is_fixed_array_init , has_val = g.gen_default_init_value (val)
1108
+ match val {
1109
+ ast.ArrayInit {
1110
+ is_fixed_array_init = it .is_fixed
1111
+ has_val = it .has_val
1112
+ }
1113
+ else {}
1114
+ }
1110
1115
is_inside_ternary := g.inside_ternary != 0
1111
1116
cur_line := if is_inside_ternary {
1112
1117
g.register_ternary_name (ident.name)
@@ -1209,33 +1214,6 @@ fn (mut g Gen) gen_cross_tmp_variable(idents []ast.Ident, val ast.Expr) {
1209
1214
}
1210
1215
}
1211
1216
1212
- fn (mut g Gen) gen_default_init_value (val ast.Expr) (bool , bool ) {
1213
- mut is_fixed_array_init := false
1214
- mut has_val := false
1215
- match val {
1216
- ast.ArrayInit {
1217
- is_fixed_array_init = it .is_fixed
1218
- has_val = it .has_val
1219
- elem_type_str := g.typ (it .elem_type)
1220
- if it .has_default {
1221
- g.gen_default_init_value (it .default_expr)
1222
- g.write ('$elem_type_str _val_$it.pos.pos = ' )
1223
- g.expr (it .default_expr)
1224
- g.writeln (';' )
1225
- } else if it .has_len && it .elem_type == table.string_type {
1226
- g.writeln ('$elem_type_str _val_$it.pos.pos = tos_lit("");' )
1227
- }
1228
- }
1229
- ast.StructInit {
1230
- for field in it .fields {
1231
- g.gen_default_init_value (field.expr)
1232
- }
1233
- }
1234
- else {}
1235
- }
1236
- return is_fixed_array_init, has_val
1237
- }
1238
-
1239
1217
fn (mut g Gen) register_ternary_name (name string ) {
1240
1218
level_key := g.inside_ternary.str ()
1241
1219
if level_key ! in g.ternary_level_names {
@@ -4348,9 +4326,17 @@ fn (mut g Gen) array_init(it ast.ArrayInit) {
4348
4326
}
4349
4327
g.write ('sizeof($elem_type_str ), ' )
4350
4328
if is_default_array {
4351
- g.write ('_val_$it.pos.pos )' )
4352
- } else if it .has_default || (it .has_len && it .elem_type == table.string_type) {
4353
- g.write ('&_val_$it.pos.pos )' )
4329
+ g.write ('($elem_type_str []){' )
4330
+ g.expr (it .default_expr)
4331
+ g.write ('}[0])' )
4332
+ } else if it .has_default {
4333
+ g.write ('&($elem_type_str []){' )
4334
+ g.expr (it .default_expr)
4335
+ g.write ('})' )
4336
+ } else if it .has_len && it .elem_type == table.string_type {
4337
+ g.write ('&($elem_type_str []){' )
4338
+ g.write ('tos_lit("")' )
4339
+ g.write ('})' )
4354
4340
} else {
4355
4341
g.write ('0)' )
4356
4342
}
0 commit comments