@@ -725,7 +725,8 @@ fn (mut g Gen) gen_struct_enc_dec(utyp ast.Type, type_info ast.TypeInfo, styp st
725
725
dec.writeln ('\t\t ${prefix}${op}${c_name(field.name)} = ${dec_name} (jsonroot_${tmp} );' )
726
726
if field.has_default_expr {
727
727
dec.writeln ('\t } else {' )
728
- dec.writeln ('\t\t ${prefix}${op}${c_name(field.name)} = ${g.expr_string(field.default_expr)} ;' )
728
+ dec.writeln ('\t\t ${prefix}${op}${c_name(field.name)} = ${g.expr_string_opt(field.typ,
729
+ field.default_expr)};' )
729
730
}
730
731
dec.writeln ('\t }' )
731
732
} else if field_sym.kind == .enum {
@@ -759,7 +760,8 @@ fn (mut g Gen) gen_struct_enc_dec(utyp ast.Type, type_info ast.TypeInfo, styp st
759
760
}
760
761
if field.has_default_expr {
761
762
dec.writeln ('\t } else {' )
762
- dec.writeln ('\t\t ${prefix}${op}${c_name(field.name)} = ${g.expr_string(field.default_expr)} ;' )
763
+ dec.writeln ('\t\t ${prefix}${op}${c_name(field.name)} = ${g.expr_string_opt(field.typ,
764
+ field.default_expr)};' )
763
765
}
764
766
dec.writeln ('\t }' )
765
767
} else if field_sym.name == 'time.Time' {
@@ -771,7 +773,8 @@ fn (mut g Gen) gen_struct_enc_dec(utyp ast.Type, type_info ast.TypeInfo, styp st
771
773
dec.writeln ('\t\t ${prefix}${op}${c_name(field.name)} = time__unix(json__decode_u64(jsonroot_${tmp} ));' )
772
774
if field.has_default_expr {
773
775
dec.writeln ('\t } else {' )
774
- dec.writeln ('\t\t ${prefix}${op}${c_name(field.name)} = ${g.expr_string(field.default_expr)} ;' )
776
+ dec.writeln ('\t\t ${prefix}${op}${c_name(field.name)} = ${g.expr_string_opt(field.typ,
777
+ field.default_expr)};' )
775
778
}
776
779
dec.writeln ('\t }' )
777
780
} else if field_sym.kind == .alias {
@@ -792,7 +795,8 @@ fn (mut g Gen) gen_struct_enc_dec(utyp ast.Type, type_info ast.TypeInfo, styp st
792
795
dec.writeln ('\t\t ${prefix}${op}${c_name(field.name)} = ${parent_dec_name} (jsonroot_${tmp} );' )
793
796
if field.has_default_expr {
794
797
dec.writeln ('\t } else {' )
795
- dec.writeln ('\t\t ${prefix}${op}${c_name(field.name)} = ${g.expr_string(field.default_expr)} ;' )
798
+ dec.writeln ('\t\t ${prefix}${op}${c_name(field.name)} = ${g.expr_string_opt(field.typ,
799
+ field.default_expr)};' )
796
800
}
797
801
dec.writeln ('\t }' )
798
802
} else {
@@ -803,7 +807,8 @@ fn (mut g Gen) gen_struct_enc_dec(utyp ast.Type, type_info ast.TypeInfo, styp st
803
807
dec.writeln ('\t\t ${prefix}${op}${c_name(field.name)} = *(${field_type} *) ${tmp} .data;' )
804
808
if field.has_default_expr {
805
809
dec.writeln ('\t } else {' )
806
- dec.writeln ('\t\t ${prefix}${op}${c_name(field.name)} = ${g.expr_string(field.default_expr)} ;' )
810
+ dec.writeln ('\t\t ${prefix}${op}${c_name(field.name)} = ${g.expr_string_opt(field.typ,
811
+ field.default_expr)};' )
807
812
}
808
813
dec.writeln ('\t }' )
809
814
}
@@ -842,7 +847,7 @@ fn (mut g Gen) gen_struct_enc_dec(utyp ast.Type, type_info ast.TypeInfo, styp st
842
847
}
843
848
if field.has_default_expr {
844
849
dec.writeln ('\t } else {' )
845
- default_str := g.expr_string ( field.default_expr)
850
+ default_str := g.expr_string_opt (field.typ, field.default_expr)
846
851
lines := default_str.count ('\n ' )
847
852
if lines > 1 {
848
853
dec.writeln (default_str.all_before_last ('\n ' ))
0 commit comments