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:
parent
514cabd7c8
commit
0470baafa6
@ -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)
|
||||
|
@ -372,3 +372,8 @@ fn test_optional_sum_type() {
|
||||
}
|
||||
assert false
|
||||
}
|
||||
|
||||
struct MultiOptionalFieldTest {
|
||||
a ?int
|
||||
b ?int
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user