1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix duplicate optional generation for struct field

This commit is contained in:
Joe Conigliaro 2021-02-22 00:00:39 +11:00
parent 514cabd7c8
commit 0470baafa6
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1
2 changed files with 14 additions and 6 deletions

View File

@ -5297,13 +5297,16 @@ fn (mut g Gen) write_types(types []table.TypeSymbol) {
if field.typ.has_flag(.optional) {
// Dont use g.typ() here becuase it will register
// optional and we dont want that
last_text := g.type_definitions.after(start_pos).clone()
g.type_definitions.go_back_to(start_pos)
styp, base := g.optional_type_name(field.typ)
g.optionals << styp
g.typedefs2.writeln('typedef struct $styp $styp;')
g.type_definitions.writeln('${g.optional_type_text(styp, base)};')
g.type_definitions.write(last_text)
if styp !in g.optionals {
last_text := g.type_definitions.after(start_pos).clone()
g.type_definitions.go_back_to(start_pos)
g.optionals << styp
g.typedefs2.writeln('typedef struct $styp $styp;')
g.type_definitions.writeln('${g.optional_type_text(styp,
base)};')
g.type_definitions.write(last_text)
}
}
type_name := g.typ(field.typ)
field_name := c_name(field.name)

View File

@ -372,3 +372,8 @@ fn test_optional_sum_type() {
}
assert false
}
struct MultiOptionalFieldTest {
a ?int
b ?int
}