mirror of
https://github.com/vlang/v.git
synced 2025-09-15 10:27:19 -04:00
cgen: cleanup in struct_init_field() (#19259)
This commit is contained in:
parent
5848610453
commit
a8d2a990c7
@ -1313,13 +1313,13 @@ fn (mut g Gen) write_prepared_it(inp_info ast.Array, inp_elem_type string, tmp s
|
||||
|
||||
fn (mut g Gen) fixed_array_var_init(expr ast.Expr, size int) {
|
||||
g.write('{')
|
||||
for idx in 0 .. size {
|
||||
for i in 0 .. size {
|
||||
if expr.is_auto_deref_var() {
|
||||
g.write('*')
|
||||
}
|
||||
g.expr(expr)
|
||||
g.write('[${idx}]')
|
||||
if idx != size - 1 {
|
||||
g.write('[${i}]')
|
||||
if i != size - 1 {
|
||||
g.write(', ')
|
||||
}
|
||||
}
|
||||
|
@ -556,17 +556,9 @@ fn (mut g Gen) struct_init_field(sfield ast.StructInitField, language ast.Langua
|
||||
inside_cast_in_heap := g.inside_cast_in_heap
|
||||
g.inside_cast_in_heap = 0 // prevent use of pointers in child structs
|
||||
|
||||
if field_type_sym.kind == .array_fixed && sfield.expr is ast.Ident {
|
||||
fixed_array_info := field_type_sym.info as ast.ArrayFixed
|
||||
g.write('{')
|
||||
for i in 0 .. fixed_array_info.size {
|
||||
g.expr(sfield.expr)
|
||||
g.write('[${i}]')
|
||||
if i != fixed_array_info.size - 1 {
|
||||
g.write(', ')
|
||||
}
|
||||
}
|
||||
g.write('}')
|
||||
if field_type_sym.kind == .array_fixed && sfield.expr in [ast.Ident, ast.SelectorExpr] {
|
||||
info := field_type_sym.info as ast.ArrayFixed
|
||||
g.fixed_array_var_init(sfield.expr, info.size)
|
||||
} else {
|
||||
if sfield.typ != ast.voidptr_type && sfield.typ != ast.nil_type
|
||||
&& (sfield.expected_type.is_ptr() && !sfield.expected_type.has_flag(.shared_f))
|
||||
|
Loading…
x
Reference in New Issue
Block a user