@@ -77,7 +77,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
77
77
g.write (')' )
78
78
}
79
79
}
80
- if is_anon {
80
+ if is_anon && ! node.typ. has_flag (.option) {
81
81
if node.language == .v {
82
82
g.write ('(${styp} )' )
83
83
}
@@ -541,7 +541,7 @@ fn (mut g Gen) zero_struct_field(field ast.StructField) bool {
541
541
return true
542
542
}
543
543
544
- fn (mut g Gen) struct_decl (s ast.Struct, name string , is_anon bool ) {
544
+ fn (mut g Gen) struct_decl (s ast.Struct, name string , is_anon bool , is_option bool ) {
545
545
if s.is_generic {
546
546
return
547
547
}
@@ -585,10 +585,11 @@ fn (mut g Gen) struct_decl(s ast.Struct, name string, is_anon bool) {
585
585
}
586
586
}
587
587
if is_anon {
588
+ option_prefix := if is_option { '_option_' } else { '' }
588
589
if s.is_shared {
589
- g.type_definitions.write_string ('\t __shared__ ${name} * ' )
590
+ g.type_definitions.write_string ('\t ${option_prefix} __shared__ ${name} * ' )
590
591
} else {
591
- g.type_definitions.write_string ('\t ${name} ' )
592
+ g.type_definitions.write_string ('\t ${option_prefix}${ name} ' )
592
593
}
593
594
return
594
595
} else if s.is_union {
@@ -671,7 +672,7 @@ fn (mut g Gen) struct_decl(s ast.Struct, name string, is_anon bool) {
671
672
if field_sym.info.is_anon {
672
673
field_is_anon = true
673
674
// Recursively generate code for this anon struct (this is the field's type)
674
- g.struct_decl (field_sym.info, field_sym.cname, true )
675
+ g.struct_decl (field_sym.info, field_sym.cname, true , field.typ. has_flag (.option) )
675
676
// Now the field's name
676
677
g.type_definitions.writeln (' ${field_name}${size_suffix} ;' )
677
678
}
0 commit comments