Skip to content

Commit f1645ff

Browse files
echistyakovfacebook-github-bot
authored andcommitted
Use reflect codec for testset.thrift
Summary: Reattempt of D73820947, but this time with a missing fix for unions. Reviewed By: a-lafrance Differential Revision: D74633836 fbshipit-source-id: 370ad63ef80a2fce89c16f6f2fcb59d5524db405
1 parent a0f24d2 commit f1645ff

File tree

10 files changed

+22
-17
lines changed

10 files changed

+22
-17
lines changed

third-party/thrift/src/thrift/compiler/generate/templates/go/types/struct_method_write.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
func (x *{{struct:go_name}}) Write(p thrift.Encoder) error {
2323
{{#struct:union?}}
2424
if countSet := x.countSetFields(); countSet > 1 {
25-
return fmt.Errorf("%T write union: no more than one field must be set (%d set).", x, countSet)
25+
return fmt.Errorf("{{struct:go_name}} write union: no more than one field must be set (%d set).", countSet)
2626
}
2727
{{/struct:union?}}
2828
if err := p.WriteStructBegin("{{struct:name}}"); err != nil {

third-party/thrift/src/thrift/compiler/generate/templates/go/types/struct_method_write_v2.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
2121
}}
2222
func (x *{{struct:go_name}}) Write(p thrift.Encoder) error {
23+
{{#struct:union?}}
24+
if countSet := x.countSetFields(); countSet > 1 {
25+
return fmt.Errorf("{{struct:go_name}} write union: no more than one field must be set (%d set).", countSet)
26+
}
27+
{{/struct:union?}}
2328
return thrift.WriteStructSpec(p, x, x.getStructSpec())
2429
}
2530
{{!newline}}

third-party/thrift/src/thrift/compiler/test/fixtures/adapter/out/go/gen-go/module/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,7 +2774,7 @@ func (x *Baz) CountSetFieldsBaz() int {
27742774

27752775
func (x *Baz) Write(p thrift.Encoder) error {
27762776
if countSet := x.countSetFields(); countSet > 1 {
2777-
return fmt.Errorf("%T write union: no more than one field must be set (%d set).", x, countSet)
2777+
return fmt.Errorf("Baz write union: no more than one field must be set (%d set).", countSet)
27782778
}
27792779
if err := p.WriteStructBegin("Baz"); err != nil {
27802780
return thrift.PrependError("Baz write struct begin error: ", err)
@@ -6888,7 +6888,7 @@ func (x *AdaptTestUnion) CountSetFieldsAdaptTestUnion() int {
68886888

68896889
func (x *AdaptTestUnion) Write(p thrift.Encoder) error {
68906890
if countSet := x.countSetFields(); countSet > 1 {
6891-
return fmt.Errorf("%T write union: no more than one field must be set (%d set).", x, countSet)
6891+
return fmt.Errorf("AdaptTestUnion write union: no more than one field must be set (%d set).", countSet)
68926892
}
68936893
if err := p.WriteStructBegin("AdaptTestUnion"); err != nil {
68946894
return thrift.PrependError("AdaptTestUnion write struct begin error: ", err)

third-party/thrift/src/thrift/compiler/test/fixtures/basic-annotations/out/go/gen-go/module/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func (x *MyUnion) CountSetFieldsMyUnion() int {
306306

307307
func (x *MyUnion) Write(p thrift.Encoder) error {
308308
if countSet := x.countSetFields(); countSet > 1 {
309-
return fmt.Errorf("%T write union: no more than one field must be set (%d set).", x, countSet)
309+
return fmt.Errorf("MyUnion write union: no more than one field must be set (%d set).", countSet)
310310
}
311311
if err := p.WriteStructBegin("MyUnion"); err != nil {
312312
return thrift.PrependError("MyUnion write struct begin error: ", err)

third-party/thrift/src/thrift/compiler/test/fixtures/basic/out/go/gen-go/module/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ func (x *MyUnion) CountSetFieldsMyUnion() int {
13911391

13921392
func (x *MyUnion) Write(p thrift.Encoder) error {
13931393
if countSet := x.countSetFields(); countSet > 1 {
1394-
return fmt.Errorf("%T write union: no more than one field must be set (%d set).", x, countSet)
1394+
return fmt.Errorf("MyUnion write union: no more than one field must be set (%d set).", countSet)
13951395
}
13961396
if err := p.WriteStructBegin("MyUnion"); err != nil {
13971397
return thrift.PrependError("MyUnion write struct begin error: ", err)
@@ -2248,7 +2248,7 @@ func (x *UnionToBeRenamed) CountSetFieldsUnionToBeRenamed() int {
22482248

22492249
func (x *UnionToBeRenamed) Write(p thrift.Encoder) error {
22502250
if countSet := x.countSetFields(); countSet > 1 {
2251-
return fmt.Errorf("%T write union: no more than one field must be set (%d set).", x, countSet)
2251+
return fmt.Errorf("UnionToBeRenamed write union: no more than one field must be set (%d set).", countSet)
22522252
}
22532253
if err := p.WriteStructBegin("UnionToBeRenamed"); err != nil {
22542254
return thrift.PrependError("UnionToBeRenamed write struct begin error: ", err)

third-party/thrift/src/thrift/compiler/test/fixtures/complex-union/out/go/gen-go/module/types.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ func (x *ComplexUnion) CountSetFieldsComplexUnion() int {
503503

504504
func (x *ComplexUnion) Write(p thrift.Encoder) error {
505505
if countSet := x.countSetFields(); countSet > 1 {
506-
return fmt.Errorf("%T write union: no more than one field must be set (%d set).", x, countSet)
506+
return fmt.Errorf("ComplexUnion write union: no more than one field must be set (%d set).", countSet)
507507
}
508508
if err := p.WriteStructBegin("ComplexUnion"); err != nil {
509509
return thrift.PrependError("ComplexUnion write struct begin error: ", err)
@@ -785,7 +785,7 @@ func (x *ListUnion) CountSetFieldsListUnion() int {
785785

786786
func (x *ListUnion) Write(p thrift.Encoder) error {
787787
if countSet := x.countSetFields(); countSet > 1 {
788-
return fmt.Errorf("%T write union: no more than one field must be set (%d set).", x, countSet)
788+
return fmt.Errorf("ListUnion write union: no more than one field must be set (%d set).", countSet)
789789
}
790790
if err := p.WriteStructBegin("ListUnion"); err != nil {
791791
return thrift.PrependError("ListUnion write struct begin error: ", err)
@@ -990,7 +990,7 @@ func (x *DataUnion) CountSetFieldsDataUnion() int {
990990

991991
func (x *DataUnion) Write(p thrift.Encoder) error {
992992
if countSet := x.countSetFields(); countSet > 1 {
993-
return fmt.Errorf("%T write union: no more than one field must be set (%d set).", x, countSet)
993+
return fmt.Errorf("DataUnion write union: no more than one field must be set (%d set).", countSet)
994994
}
995995
if err := p.WriteStructBegin("DataUnion"); err != nil {
996996
return thrift.PrependError("DataUnion write struct begin error: ", err)
@@ -1419,7 +1419,7 @@ func (x *ValUnion) CountSetFieldsValUnion() int {
14191419

14201420
func (x *ValUnion) Write(p thrift.Encoder) error {
14211421
if countSet := x.countSetFields(); countSet > 1 {
1422-
return fmt.Errorf("%T write union: no more than one field must be set (%d set).", x, countSet)
1422+
return fmt.Errorf("ValUnion write union: no more than one field must be set (%d set).", countSet)
14231423
}
14241424
if err := p.WriteStructBegin("ValUnion"); err != nil {
14251425
return thrift.PrependError("ValUnion write struct begin error: ", err)
@@ -1625,7 +1625,7 @@ func (x *VirtualComplexUnion) CountSetFieldsVirtualComplexUnion() int {
16251625

16261626
func (x *VirtualComplexUnion) Write(p thrift.Encoder) error {
16271627
if countSet := x.countSetFields(); countSet > 1 {
1628-
return fmt.Errorf("%T write union: no more than one field must be set (%d set).", x, countSet)
1628+
return fmt.Errorf("VirtualComplexUnion write union: no more than one field must be set (%d set).", countSet)
16291629
}
16301630
if err := p.WriteStructBegin("VirtualComplexUnion"); err != nil {
16311631
return thrift.PrependError("VirtualComplexUnion write struct begin error: ", err)
@@ -1895,7 +1895,7 @@ func (x *NonCopyableUnion) CountSetFieldsNonCopyableUnion() int {
18951895

18961896
func (x *NonCopyableUnion) Write(p thrift.Encoder) error {
18971897
if countSet := x.countSetFields(); countSet > 1 {
1898-
return fmt.Errorf("%T write union: no more than one field must be set (%d set).", x, countSet)
1898+
return fmt.Errorf("NonCopyableUnion write union: no more than one field must be set (%d set).", countSet)
18991899
}
19001900
if err := p.WriteStructBegin("NonCopyableUnion"); err != nil {
19011901
return thrift.PrependError("NonCopyableUnion write struct begin error: ", err)

third-party/thrift/src/thrift/compiler/test/fixtures/constants/out/go/gen-go/module/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,7 @@ func (x *Union1) CountSetFieldsUnion1() int {
18821882

18831883
func (x *Union1) Write(p thrift.Encoder) error {
18841884
if countSet := x.countSetFields(); countSet > 1 {
1885-
return fmt.Errorf("%T write union: no more than one field must be set (%d set).", x, countSet)
1885+
return fmt.Errorf("Union1 write union: no more than one field must be set (%d set).", countSet)
18861886
}
18871887
if err := p.WriteStructBegin("union1"); err != nil {
18881888
return thrift.PrependError("Union1 write struct begin error: ", err)
@@ -2202,7 +2202,7 @@ func (x *Union2) CountSetFieldsUnion2() int {
22022202

22032203
func (x *Union2) Write(p thrift.Encoder) error {
22042204
if countSet := x.countSetFields(); countSet > 1 {
2205-
return fmt.Errorf("%T write union: no more than one field must be set (%d set).", x, countSet)
2205+
return fmt.Errorf("Union2 write union: no more than one field must be set (%d set).", countSet)
22062206
}
22072207
if err := p.WriteStructBegin("union2"); err != nil {
22082208
return thrift.PrependError("Union2 write struct begin error: ", err)

third-party/thrift/src/thrift/compiler/test/fixtures/doctext/out/go/gen-go/module/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func (x *U) CountSetFieldsU() int {
355355

356356
func (x *U) Write(p thrift.Encoder) error {
357357
if countSet := x.countSetFields(); countSet > 1 {
358-
return fmt.Errorf("%T write union: no more than one field must be set (%d set).", x, countSet)
358+
return fmt.Errorf("U write union: no more than one field must be set (%d set).", countSet)
359359
}
360360
if err := p.WriteStructBegin("U"); err != nil {
361361
return thrift.PrependError("U write struct begin error: ", err)

third-party/thrift/src/thrift/compiler/test/fixtures/empty-struct/out/go/gen-go/module/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (x *Nada) CountSetFieldsNada() int {
111111

112112
func (x *Nada) Write(p thrift.Encoder) error {
113113
if countSet := x.countSetFields(); countSet > 1 {
114-
return fmt.Errorf("%T write union: no more than one field must be set (%d set).", x, countSet)
114+
return fmt.Errorf("Nada write union: no more than one field must be set (%d set).", countSet)
115115
}
116116
if err := p.WriteStructBegin("Nada"); err != nil {
117117
return thrift.PrependError("Nada write struct begin error: ", err)

third-party/thrift/src/thrift/compiler/test/fixtures/terse_write/out/go/gen-go/terse_write/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ func (x *MyUnion) CountSetFieldsMyUnion() int {
10601060

10611061
func (x *MyUnion) Write(p thrift.Encoder) error {
10621062
if countSet := x.countSetFields(); countSet > 1 {
1063-
return fmt.Errorf("%T write union: no more than one field must be set (%d set).", x, countSet)
1063+
return fmt.Errorf("MyUnion write union: no more than one field must be set (%d set).", countSet)
10641064
}
10651065
if err := p.WriteStructBegin("MyUnion"); err != nil {
10661066
return thrift.PrependError("MyUnion write struct begin error: ", err)

0 commit comments

Comments
 (0)