Skip to content

Commit

Permalink
bugfix: empty structs/unions/exceptions failed to compile
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav committed Mar 29, 2016
1 parent f9a4b99 commit a29192c
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gen/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ func (f fieldGroupGenerator) FromWire(g Generator) error {
<$v := newVar "v">
<$w := newVar "w">
func (<$v> *<.Name>) FromWire(<$w> <$wire>.Value) error {
var err error
<if len .Fields>
var err error
<end>
<$f := newVar "field">
for _, <$f> := range <$w>.GetStruct().Fields {
switch <$f>.ID {
Expand Down
30 changes: 30 additions & 0 deletions gen/struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,3 +647,33 @@ func TestUnionFromWireInconsistencies(t *testing.T) {
}
}
}

func TestEmptyStruct(t *testing.T) {
var x, y ts.EmptyStruct
v := wire.NewValueStruct(wire.Struct{Fields: []wire.Field{}})

assert.Equal(t, x.ToWire(), v)
if assert.NoError(t, y.FromWire(v)) {
assert.Equal(t, x, y)
}
}

func TestEmptyUnion(t *testing.T) {
var x, y tu.EmptyUnion
v := wire.NewValueStruct(wire.Struct{Fields: []wire.Field{}})

assert.Equal(t, x.ToWire(), v)
if assert.NoError(t, y.FromWire(v)) {
assert.Equal(t, x, y)
}
}

func TestEmptyException(t *testing.T) {
var x, y tx.EmptyException
v := wire.NewValueStruct(wire.Struct{Fields: []wire.Field{}})

assert.Equal(t, x.ToWire(), v)
if assert.NoError(t, y.FromWire(v)) {
assert.Equal(t, x, y)
}
}
12 changes: 12 additions & 0 deletions gen/testdata/enums/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions gen/testdata/exceptions/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions gen/testdata/structs/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions gen/testdata/thrift/enums.thrift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enum EmptyEnum {}

enum EnumDefault {
Foo, Bar, Baz
}
Expand Down
2 changes: 2 additions & 0 deletions gen/testdata/thrift/exceptions.thrift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
exception EmptyException {}

exception DoesNotExistException {
1: required string key
}
2 changes: 2 additions & 0 deletions gen/testdata/thrift/structs.thrift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
struct EmptyStruct {}

//////////////////////////////////////////////////////////////////////////////
// Structs with primitives

Expand Down
2 changes: 2 additions & 0 deletions gen/testdata/thrift/unions.thrift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
include "./typedefs.thrift"

union EmptyUnion {}

union Document {
1: typedefs.PDF pdf
2: string plainText
Expand Down
20 changes: 20 additions & 0 deletions gen/testdata/unions/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a29192c

Please sign in to comment.