Tom Deering created THRIFT-3703:
-----------------------------------
Summary: Unions Enforce Count == 1 Only For Struct Members
Key: THRIFT-3703
URL: https://issues.apache.org/jira/browse/THRIFT-3703
Project: Thrift
Issue Type: Bug
Components: Go - Compiler
Affects Versions: 0.9.3
Environment: Ubuntu 15.10
Reporter: Tom Deering
Go code for unions generated by Thrift 0.9.3 fails to consider map fields of a
union when enforcing that the number of fields set is 1. For example:
{code}
union Foo{
1: map<bool, bool> u1,
2: bool u2,
}
{code}
Produces Go code:
{code}
type Foo struct {
U1 map[bool]bool `thrift:"u1,1" json:"u1,omitempty"`
U2 *bool `thrift:"u2,2" json:"u2,omitempty"`
}
func (p *Foo) CountSetFieldsFoo() int {
count := 0
if p.IsSetU2() {
count++
}
return count
}
...
func (p *Foo) Write(oprot thrift.TProtocol) error {
if c := p.CountSetFieldsFoo(); c != 1 {
return fmt.Errorf("%T write union: exactly one field must be
set (%d set).", p, c)
}
...
{code}
Due to this bug, Thrift will complain that a union with only field u1 set has
no fields set.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)