Skip to content

Commit 65f27bc

Browse files
committed
Make union fields all optional
1 parent 4ae4123 commit 65f27bc

File tree

3 files changed

+526
-505
lines changed

3 files changed

+526
-505
lines changed

parser/grammar.peg

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ func ifaceSliceToString(v interface{}) string {
4040
}
4141
return string(b)
4242
}
43+
44+
// toStruct converts a union to a struct with all fields optional.
45+
func unionToStruct(u union) *Struct {
46+
st := (*Struct)(u)
47+
for _, f := range st.Fields {
48+
f.Optional = true
49+
}
50+
return st
51+
}
4352
}
4453

4554
Grammar ← __ statements:( Statement __ )* (EOF / SyntaxError) {
@@ -70,7 +79,7 @@ Grammar ← __ statements:( Statement __ )* (EOF / SyntaxError) {
7079
case exception:
7180
thrift.Exceptions[v.Name] = (*Struct)(v)
7281
case union:
73-
thrift.Unions[v.Name] = (*Struct)(v)
82+
thrift.Unions[v.Name] = unionToStruct(v)
7483
case *Service:
7584
thrift.Services[v.Name] = v
7685
case include:

0 commit comments

Comments
 (0)