cgen: fix duplicate optional generation for struct field
parent
514cabd7c8
commit
0470baafa6
|
@ -5297,14 +5297,17 @@ fn (mut g Gen) write_types(types []table.TypeSymbol) {
|
||||||
if field.typ.has_flag(.optional) {
|
if field.typ.has_flag(.optional) {
|
||||||
// Dont use g.typ() here becuase it will register
|
// Dont use g.typ() here becuase it will register
|
||||||
// optional and we dont want that
|
// optional and we dont want that
|
||||||
|
styp, base := g.optional_type_name(field.typ)
|
||||||
|
if styp !in g.optionals {
|
||||||
last_text := g.type_definitions.after(start_pos).clone()
|
last_text := g.type_definitions.after(start_pos).clone()
|
||||||
g.type_definitions.go_back_to(start_pos)
|
g.type_definitions.go_back_to(start_pos)
|
||||||
styp, base := g.optional_type_name(field.typ)
|
|
||||||
g.optionals << styp
|
g.optionals << styp
|
||||||
g.typedefs2.writeln('typedef struct $styp $styp;')
|
g.typedefs2.writeln('typedef struct $styp $styp;')
|
||||||
g.type_definitions.writeln('${g.optional_type_text(styp, base)};')
|
g.type_definitions.writeln('${g.optional_type_text(styp,
|
||||||
|
base)};')
|
||||||
g.type_definitions.write(last_text)
|
g.type_definitions.write(last_text)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
type_name := g.typ(field.typ)
|
type_name := g.typ(field.typ)
|
||||||
field_name := c_name(field.name)
|
field_name := c_name(field.name)
|
||||||
g.type_definitions.writeln('\t$type_name $field_name;')
|
g.type_definitions.writeln('\t$type_name $field_name;')
|
||||||
|
|
|
@ -372,3 +372,8 @@ fn test_optional_sum_type() {
|
||||||
}
|
}
|
||||||
assert false
|
assert false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct MultiOptionalFieldTest {
|
||||||
|
a ?int
|
||||||
|
b ?int
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue