cgen: cleanup label comments in the generated C code (#22962)

This commit is contained in:
Felipe Pena 2024-11-24 19:29:59 -03:00 committed by GitHub
parent e86b526947
commit 18d514f429
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 40 additions and 47 deletions

View File

@ -253,5 +253,4 @@ fn (mut g Gen) gen_assert_single_expr(expr ast.Expr, typ ast.Type) {
} }
} }
} }
g.write(' /* typeof: ' + expr.type_name() + ' type: ' + typ.str() + ' */ ')
} }

View File

@ -795,7 +795,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
g.expr(left) g.expr(left)
g.write(', ${final_ref_str}') g.write(', ${final_ref_str}')
g.expr(val) g.expr(val)
g.write(', sizeof(${typ_str})) /*assign*/') g.write(', sizeof(${typ_str}))')
} }
} }
} else if is_decl { } else if is_decl {
@ -1045,7 +1045,7 @@ fn (mut g Gen) gen_cross_var_assign(node &ast.AssignStmt) {
} }
needs_clone := info.elem_type == ast.string_type && g.is_autofree needs_clone := info.elem_type == ast.string_type && g.is_autofree
if needs_clone { if needs_clone {
g.write('/*2*/string_clone(') g.write('string_clone(')
} }
g.expr(left) g.expr(left)
if needs_clone { if needs_clone {

View File

@ -985,7 +985,7 @@ pub fn (mut g Gen) write_typeof_functions() {
if sum_info.is_generic { if sum_info.is_generic {
continue continue
} }
g.writeln('${static_prefix}char * v_typeof_sumtype_${sym.cname}(int sidx) { /* ${sym.name} */ ') g.writeln('${static_prefix}char * v_typeof_sumtype_${sym.cname}(int sidx) {')
if g.pref.build_mode == .build_module { if g.pref.build_mode == .build_module {
g.writeln('\t\tif( sidx == _v_type_idx_${sym.cname}() ) return "${util.strip_main_name(sym.name)}";') g.writeln('\t\tif( sidx == _v_type_idx_${sym.cname}() ) return "${util.strip_main_name(sym.name)}";')
for v in sum_info.variants { for v in sum_info.variants {
@ -1011,7 +1011,7 @@ pub fn (mut g Gen) write_typeof_functions() {
g.writeln('\t}') g.writeln('\t}')
} }
g.writeln2('}', '') g.writeln2('}', '')
g.writeln('${static_prefix}int v_typeof_sumtype_idx_${sym.cname}(int sidx) { /* ${sym.name} */ ') g.writeln('${static_prefix}int v_typeof_sumtype_idx_${sym.cname}(int sidx) {')
if g.pref.build_mode == .build_module { if g.pref.build_mode == .build_module {
g.writeln('\t\tif( sidx == _v_type_idx_${sym.cname}() ) return ${int(ityp)};') g.writeln('\t\tif( sidx == _v_type_idx_${sym.cname}() ) return ${int(ityp)};')
for v in sum_info.variants { for v in sum_info.variants {
@ -1042,7 +1042,7 @@ pub fn (mut g Gen) write_typeof_functions() {
continue continue
} }
g.definitions.writeln('static char * v_typeof_interface_${sym.cname}(int sidx);') g.definitions.writeln('static char * v_typeof_interface_${sym.cname}(int sidx);')
g.writeln('static char * v_typeof_interface_${sym.cname}(int sidx) { /* ${sym.name} */ ') g.writeln('static char * v_typeof_interface_${sym.cname}(int sidx) {')
for t in inter_info.types { for t in inter_info.types {
sub_sym := g.table.sym(ast.mktyp(t)) sub_sym := g.table.sym(ast.mktyp(t))
if sub_sym.info is ast.Struct && sub_sym.info.is_unresolved_generic() { if sub_sym.info is ast.Struct && sub_sym.info.is_unresolved_generic() {
@ -1051,7 +1051,7 @@ pub fn (mut g Gen) write_typeof_functions() {
g.writeln('\tif (sidx == _${sym.cname}_${sub_sym.cname}_index) return "${util.strip_main_name(sub_sym.name)}";') g.writeln('\tif (sidx == _${sym.cname}_${sub_sym.cname}_index) return "${util.strip_main_name(sub_sym.name)}";')
} }
g.writeln2('\treturn "unknown ${util.strip_main_name(sym.name)}";', '}') g.writeln2('\treturn "unknown ${util.strip_main_name(sym.name)}";', '}')
g.writeln2('', 'static int v_typeof_interface_idx_${sym.cname}(int sidx) { /* ${sym.name} */ ') g.writeln2('', 'static int v_typeof_interface_idx_${sym.cname}(int sidx) {')
for t in inter_info.types { for t in inter_info.types {
sub_sym := g.table.sym(ast.mktyp(t)) sub_sym := g.table.sym(ast.mktyp(t))
if sub_sym.info is ast.Struct && sub_sym.info.is_unresolved_generic() { if sub_sym.info is ast.Struct && sub_sym.info.is_unresolved_generic() {
@ -3745,7 +3745,6 @@ fn (mut g Gen) expr(node_ ast.Expr) {
g.write(')') g.write(')')
if gen_or { if gen_or {
if !node.is_option { if !node.is_option {
g.write('/*JJJ*/')
g.or_block(tmp_opt, node.or_block, elem_type) g.or_block(tmp_opt, node.or_block, elem_type)
} }
if is_gen_or_and_assign_rhs { if is_gen_or_and_assign_rhs {
@ -3877,7 +3876,7 @@ fn (mut g Gen) typeof_expr(node ast.TypeOf) {
if sym.kind == .sum_type { if sym.kind == .sum_type {
// When encountering a .sum_type, typeof() should be done at runtime, // When encountering a .sum_type, typeof() should be done at runtime,
// because the subtype of the expression may change: // because the subtype of the expression may change:
g.write('charptr_vstring_literal( /* ${sym.name} */ v_typeof_sumtype_${sym.cname}( (') g.write('charptr_vstring_literal(v_typeof_sumtype_${sym.cname}( (')
g.expr(node.expr) g.expr(node.expr)
g.write(')._typ ))') g.write(')._typ ))')
} else if sym.kind == .array_fixed { } else if sym.kind == .array_fixed {
@ -4851,7 +4850,7 @@ fn (mut g Gen) select_expr(node ast.SelectExpr) {
g.writeln('}));\n') g.writeln('}));\n')
} }
select_result := g.new_tmp_var() select_result := g.new_tmp_var()
g.write('int ${select_result} = sync__channel_select(&/*arr*/${chan_array}, ${directions_array}, &/*arr*/${objs_array}, ') g.write('int ${select_result} = sync__channel_select(&${chan_array}, ${directions_array}, &${objs_array}, ')
if has_timeout { if has_timeout {
g.expr(timeout_expr) g.expr(timeout_expr)
} else if has_else { } else if has_else {
@ -4952,7 +4951,6 @@ fn (mut g Gen) ident(node ast.Ident) {
g.write(name) g.write(name)
} }
} else { } else {
g.write('/*opt*/')
styp := g.base_type(comptime_type) styp := g.base_type(comptime_type)
if is_auto_heap { if is_auto_heap {
g.write('(*(${styp}*)${name}->data)') g.write('(*(${styp}*)${name}->data)')
@ -4998,7 +4996,6 @@ fn (mut g Gen) ident(node ast.Ident) {
g.write(name) g.write(name)
} }
} else { } else {
g.write('/*opt*/')
styp := g.base_type(node.info.typ) styp := g.base_type(node.info.typ)
if is_auto_heap { if is_auto_heap {
g.write('(*(${styp}*)${name}->data)') g.write('(*(${styp}*)${name}->data)')
@ -5106,7 +5103,7 @@ fn (mut g Gen) ident(node ast.Ident) {
g.write(closure_ctx + '->') g.write(closure_ctx + '->')
} }
if node.obj.typ.nr_muls() > 1 { if node.obj.typ.nr_muls() > 1 {
g.write2('/**/(', '*'.repeat(node.obj.typ.nr_muls() - 1)) g.write2('(', '*'.repeat(node.obj.typ.nr_muls() - 1))
g.write2(name, ')') g.write2(name, ')')
} else { } else {
g.write(name) g.write(name)
@ -7310,9 +7307,9 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty
mr_styp = 'voidptr' mr_styp = 'voidptr'
} }
if return_type.has_flag(.result) { if return_type.has_flag(.result) {
g.writeln('if (${cvar_name}.is_error) {') // /*or block*/ ') g.writeln('if (${cvar_name}.is_error) {')
} else { } else {
g.writeln('if (${cvar_name}.state != 0) {') // /*or block*/ ') g.writeln('if (${cvar_name}.state != 0) {')
} }
} }
if or_block.kind == .block { if or_block.kind == .block {
@ -7711,9 +7708,9 @@ fn (mut g Gen) as_cast(node ast.AsCast) {
g.expr(node.expr) g.expr(node.expr)
g.write('; ') g.write('; ')
if sym.info is ast.FnType { if sym.info is ast.FnType {
g.write('/* as */ (${styp})__as_cast(') g.write('(${styp})__as_cast(')
} else { } else {
g.write('/* as */ *(${styp}*)__as_cast(') g.write('*(${styp}*)__as_cast(')
} }
g.write2(tmp_var, dot) g.write2(tmp_var, dot)
g.write2('_${sym.cname},', tmp_var) g.write2('_${sym.cname},', tmp_var)
@ -7722,9 +7719,9 @@ fn (mut g Gen) as_cast(node ast.AsCast) {
g.write('_typ, ${sidx}); })') g.write('_typ, ${sidx}); })')
} else { } else {
if sym.info is ast.FnType { if sym.info is ast.FnType {
g.write('/* as */ (${styp})__as_cast(') g.write('(${styp})__as_cast(')
} else { } else {
g.write('/* as */ *(${styp}*)__as_cast(') g.write('*(${styp}*)__as_cast(')
} }
g.write('(') g.write('(')
g.expr(node.expr) g.expr(node.expr)
@ -7771,9 +7768,9 @@ fn (mut g Gen) as_cast(node ast.AsCast) {
g.expr(node.expr) g.expr(node.expr)
g.write('; ') g.write('; ')
if sym.info is ast.FnType { if sym.info is ast.FnType {
g.write('/* as */ (${styp})__as_cast(') g.write('(${styp})__as_cast(')
} else { } else {
g.write('/* as */ *(${styp}*)__as_cast(') g.write('*(${styp}*)__as_cast(')
} }
g.write2(tmp_var, dot) g.write2(tmp_var, dot)
g.write('_${sym.cname},v_typeof_interface_idx_${expr_type_sym.cname}(') g.write('_${sym.cname},v_typeof_interface_idx_${expr_type_sym.cname}(')
@ -7782,9 +7779,9 @@ fn (mut g Gen) as_cast(node ast.AsCast) {
g.write('_typ), ${sidx}); })') g.write('_typ), ${sidx}); })')
} else { } else {
if sym.info is ast.FnType { if sym.info is ast.FnType {
g.write('/* as */ (${styp})__as_cast(') g.write('(${styp})__as_cast(')
} else { } else {
g.write('/* as */ *(${styp}*)__as_cast(') g.write('*(${styp}*)__as_cast(')
} }
g.write('(') g.write('(')
g.expr(node.expr) g.expr(node.expr)
@ -7927,9 +7924,7 @@ fn (mut g Gen) interface_table() string {
} else { } else {
// the field is embedded in another struct // the field is embedded in another struct
cast_struct.write_string('\t\t.${cname} = (${field_styp}*)((char*)x') cast_struct.write_string('\t\t.${cname} = (${field_styp}*)((char*)x')
if st == ast.voidptr_type || st == ast.nil_type { if st != ast.voidptr_type && st != ast.nil_type {
cast_struct.write_string('/*.... ast.voidptr_type */')
} else {
if st_sym.kind == .struct { if st_sym.kind == .struct {
if _, embeds := g.table.find_field_from_embeds(st_sym, if _, embeds := g.table.find_field_from_embeds(st_sym,
field.name) field.name)

View File

@ -1791,14 +1791,14 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
match node.name { match node.name {
'type_name' { 'type_name' {
if left_sym.kind in [.sum_type, .interface] { if left_sym.kind in [.sum_type, .interface] {
g.conversion_function_call('charptr_vstring_literal( /* ${left_sym.name} */ v_typeof_${prefix_name}_${typ_sym.cname}', g.conversion_function_call('charptr_vstring_literal(v_typeof_${prefix_name}_${typ_sym.cname}',
')', node) ')', node)
return return
} }
} }
'type_idx' { 'type_idx' {
if left_sym.kind in [.sum_type, .interface] { if left_sym.kind in [.sum_type, .interface] {
g.conversion_function_call('/* ${left_sym.name} */ v_typeof_${prefix_name}_idx_${typ_sym.cname}', g.conversion_function_call('v_typeof_${prefix_name}_idx_${typ_sym.cname}',
'', node) '', node)
return return
} }
@ -2817,24 +2817,24 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
if exp_sym.kind == .array { if exp_sym.kind == .array {
if (arg.expr is ast.Ident && arg.expr.kind == .variable) if (arg.expr is ast.Ident && arg.expr.kind == .variable)
|| arg.expr is ast.SelectorExpr { || arg.expr is ast.SelectorExpr {
g.write('&/*arr*/') g.write('&')
g.expr(arg.expr) g.expr(arg.expr)
} else { } else {
// Special case for mutable arrays. We can't `&` function // Special case for mutable arrays. We can't `&` function
// results, have to use `(array[]){ expr }[0]` hack. // results, have to use `(array[]){ expr }[0]` hack.
g.write('&/*111*/(array[]){') g.write('&(array[]){')
g.expr(arg.expr) g.expr(arg.expr)
g.write('}[0]') g.write('}[0]')
} }
return return
} else if arg_sym.kind == .sum_type && exp_sym.kind == .sum_type } else if arg_sym.kind == .sum_type && exp_sym.kind == .sum_type
&& arg.expr in [ast.Ident, ast.SelectorExpr] { && arg.expr in [ast.Ident, ast.SelectorExpr] {
g.write('&/*sum*/') g.write('&')
g.expr(arg.expr) g.expr(arg.expr)
return return
} else if arg_sym.kind == .interface && exp_sym.kind == .interface } else if arg_sym.kind == .interface && exp_sym.kind == .interface
&& arg.expr in [ast.Ident, ast.SelectorExpr] { && arg.expr in [ast.Ident, ast.SelectorExpr] {
g.write('&/*iface*/') g.write('&')
g.expr(arg.expr) g.expr(arg.expr)
return return
} }
@ -2860,7 +2860,7 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
g.write('(voidptr)') g.write('(voidptr)')
} else if !(!arg.is_mut && arg_sym.kind == .alias } else if !(!arg.is_mut && arg_sym.kind == .alias
&& g.table.unaliased_type(arg_typ).is_any_kind_of_pointer()) { && g.table.unaliased_type(arg_typ).is_any_kind_of_pointer()) {
g.write('(voidptr)&/*qq*/') g.write('(voidptr)&')
} }
} else { } else {
mut atype := expected_deref_type mut atype := expected_deref_type
@ -2868,7 +2868,7 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
atype = g.unwrap_generic(atype) atype = g.unwrap_generic(atype)
} }
if atype.has_flag(.generic) || arg.expr is ast.StructInit { if atype.has_flag(.generic) || arg.expr is ast.StructInit {
g.write('(voidptr)&/*qq2*/') g.write('(voidptr)&')
} else if arg.expr is ast.None { } else if arg.expr is ast.None {
g.expr_with_opt(arg.expr, arg_typ, expected_type) g.expr_with_opt(arg.expr, arg_typ, expected_type)
return return
@ -2879,18 +2879,18 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
if arg_typ_sym.kind in [.sum_type, .interface] { if arg_typ_sym.kind in [.sum_type, .interface] {
atype = arg_typ atype = arg_typ
} }
g.write('ADDR(${g.styp(atype)}/*qq*/, ') g.write('ADDR(${g.styp(atype)}, ')
} }
} }
} else if arg_sym.kind == .sum_type && exp_sym.kind == .sum_type { } else if arg_sym.kind == .sum_type && exp_sym.kind == .sum_type {
// Automatically passing sum types by reference if the argument expects it, // Automatically passing sum types by reference if the argument expects it,
// not only the argument is mutable. // not only the argument is mutable.
if arg.expr is ast.SelectorExpr { if arg.expr is ast.SelectorExpr {
g.write('&/*sum*/') g.write('&')
g.expr(arg.expr) g.expr(arg.expr)
return return
} else if arg.expr is ast.CastExpr { } else if arg.expr is ast.CastExpr {
g.write('ADDR(${g.styp(expected_deref_type)}/*sum*/, ') g.write('ADDR(${g.styp(expected_deref_type)}, ')
g.expr_with_cast(arg.expr, arg_typ, expected_type) g.expr_with_cast(arg.expr, arg_typ, expected_type)
g.write(')') g.write(')')
return return

View File

@ -252,7 +252,7 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
g.empty_line = true g.empty_line = true
opt_expr := '(*(${g.styp(node.cond_type.clear_flag(.option))}*)${cond_var}${op_field}data)' opt_expr := '(*(${g.styp(node.cond_type.clear_flag(.option))}*)${cond_var}${op_field}data)'
cond_expr := if node.cond_type.has_flag(.option) { cond_expr := if node.cond_type.has_flag(.option) {
'/*opt*/ ${opt_expr}${op_field}len' '${opt_expr}${op_field}len'
} else { } else {
'${cond_var}${op_field}len' '${cond_var}${op_field}len'
} }
@ -273,7 +273,7 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
// `int* val = ((int**)arr.data)[i];` // `int* val = ((int**)arr.data)[i];`
// right := if node.val_is_mut { styp } else { styp + '*' } // right := if node.val_is_mut { styp } else { styp + '*' }
right := if node.cond_type.has_flag(.option) { right := if node.cond_type.has_flag(.option) {
'/*opt*/ ((${styp}*)${opt_expr}${op_field}data)[${i}]' '((${styp}*)${opt_expr}${op_field}data)[${i}]'
} else if node.val_is_mut || node.val_is_ref { } else if node.val_is_mut || node.val_is_ref {
'((${styp})${cond_var}${op_field}data) + ${i}' '((${styp})${cond_var}${op_field}data) + ${i}'
} else { } else {
@ -370,7 +370,7 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
if node.key_var != '_' { if node.key_var != '_' {
key_styp := g.styp(node.key_type) key_styp := g.styp(node.key_type)
key := c_name(node.key_var) key := c_name(node.key_var)
g.writeln('${key_styp} ${key} = /*key*/ *(${key_styp}*)DenseArray_key(&${cond_var}${dot_or_ptr}key_values, ${idx});') g.writeln('${key_styp} ${key} = *(${key_styp}*)DenseArray_key(&${cond_var}${dot_or_ptr}key_values, ${idx});')
// TODO: analyze whether node.key_type has a .clone() method and call .clone() for all types: // TODO: analyze whether node.key_type has a .clone() method and call .clone() for all types:
if node.key_type == ast.string_type { if node.key_type == ast.string_type {
g.writeln('${key} = string_clone(${key});') g.writeln('${key} = string_clone(${key});')

View File

@ -256,7 +256,7 @@ fn (mut g Gen) index_of_array(node ast.IndexExpr, sym ast.TypeSymbol) {
} }
} else { } else {
if needs_clone { if needs_clone {
g.write('/*2*/string_clone(') g.write('string_clone(')
} }
if is_fn_index_call { if is_fn_index_call {
if elem_sym.info is ast.FnType { if elem_sym.info is ast.FnType {

View File

@ -853,7 +853,7 @@ fn (mut g Gen) infix_expr_is_op(node ast.InfixExpr) {
g.write('_typ ${cmp_op} ') g.write('_typ ${cmp_op} ')
} }
if node.right is ast.None { if node.right is ast.None {
g.write('${ast.none_type.idx()} /* none */') g.write('${ast.none_type.idx()}')
} else if node.right is ast.Ident && node.right.name == g.comptime.comptime_for_variant_var { } else if node.right is ast.Ident && node.right.name == g.comptime.comptime_for_variant_var {
variant_idx := g.comptime.type_map['${g.comptime.comptime_for_variant_var}.typ'] or { variant_idx := g.comptime.type_map['${g.comptime.comptime_for_variant_var}.typ'] or {
ast.void_type ast.void_type

View File

@ -391,7 +391,7 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st
first_variant_name := fv_sym.cname first_variant_name := fv_sym.cname
// println('KIND=${fv_sym.kind}') // println('KIND=${fv_sym.kind}')
if fv_sym.kind == .struct && !is_option && field_op != '->' { if fv_sym.kind == .struct && !is_option && field_op != '->' {
dec.writeln('/*sum type ${fv_sym.name} ret_styp=${ret_styp}*/\tif (root->type == cJSON_NULL) { ') dec.writeln('\tif (root->type == cJSON_NULL) { ')
dec.writeln('\t\tstruct ${first_variant_name} empty = {0};') dec.writeln('\t\tstruct ${first_variant_name} empty = {0};')
dec.writeln('res = ${variant_typ}_to_sumtype_${ret_styp}(&empty); } \n else ') dec.writeln('res = ${variant_typ}_to_sumtype_${ret_styp}(&empty); } \n else ')
// dec.writeln('res = ${variant_typ}_to_sumtype_${sym.cname}(&empty); } \n else ') // dec.writeln('res = ${variant_typ}_to_sumtype_${sym.cname}(&empty); } \n else ')
@ -909,9 +909,9 @@ fn (mut g Gen) gen_struct_enc_dec(utyp ast.Type, type_info ast.TypeInfo, styp st
if !field.typ.is_any_kind_of_pointer() { if !field.typ.is_any_kind_of_pointer() {
if field_sym.kind == .alias && field.typ.has_flag(.option) { if field_sym.kind == .alias && field.typ.has_flag(.option) {
parent_type := g.table.unaliased_type(field.typ).set_flag(.option) parent_type := g.table.unaliased_type(field.typ).set_flag(.option)
enc.writeln('${indent}\tcJSON_AddItemToObject(o, "${name}", ${enc_name}(*(${g.styp(parent_type)}*)&${prefix_enc}${op}${c_name(field.name)})); /*?A*/') enc.writeln('${indent}\tcJSON_AddItemToObject(o, "${name}", ${enc_name}(*(${g.styp(parent_type)}*)&${prefix_enc}${op}${c_name(field.name)}));')
} else { } else {
enc.writeln('${indent}\tcJSON_AddItemToObject(o, "${name}", ${enc_name}(${prefix_enc}${op}${c_name(field.name)})); /*A*/') enc.writeln('${indent}\tcJSON_AddItemToObject(o, "${name}", ${enc_name}(${prefix_enc}${op}${c_name(field.name)}));')
} }
} else { } else {
arg_prefix := if field.typ.is_ptr() { '' } else { '*' } arg_prefix := if field.typ.is_ptr() { '' } else { '*' }
@ -951,7 +951,7 @@ fn gen_js_get_opt(dec_name string, field_type string, styp string, tmp string, n
// dec.writeln('\t\tif (jsonroot_${tmp}->type == cJSON_NULL) { puts("${name} IS JSON_NULL"); }') // dec.writeln('\t\tif (jsonroot_${tmp}->type == cJSON_NULL) { puts("${name} IS JSON_NULL"); }')
dec.writeln('\t\t${tmp} = ${dec_name}(jsonroot_${tmp});') dec.writeln('\t\t${tmp} = ${dec_name}(jsonroot_${tmp});')
dec.writeln('\t\tif (${tmp}.is_error) {') dec.writeln('\t\tif (${tmp}.is_error) {')
dec.writeln('\t\t\treturn (${result_name}_${styp}){ /*A*/ .is_error = true, .err = ${tmp}.err, .data = {0} };') dec.writeln('\t\t\treturn (${result_name}_${styp}){ .is_error = true, .err = ${tmp}.err, .data = {0} };')
dec.writeln('\t\t}') dec.writeln('\t\t}')
dec.writeln('\t}') dec.writeln('\t}')
} }

View File

@ -669,7 +669,6 @@ fn (mut g Gen) struct_init_field(sfield ast.StructInitField, language ast.Langua
field_type_sym := g.table.sym(sfield.typ) field_type_sym := g.table.sym(sfield.typ)
mut cloned := false mut cloned := false
if g.is_autofree && !sfield.typ.is_ptr() && field_type_sym.kind in [.array, .string] { if g.is_autofree && !sfield.typ.is_ptr() && field_type_sym.kind in [.array, .string] {
g.write('/*clone1*/')
if g.gen_clone_assignment(sfield.expected_type, sfield.expr, sfield.typ, false) { if g.gen_clone_assignment(sfield.expected_type, sfield.expr, sfield.typ, false) {
cloned = true cloned = true
} }