You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Tom Deering (JIRA)" <ji...@apache.org> on 2016/03/01 22:33:18 UTC

[jira] [Commented] (THRIFT-3703) Unions Field Count Does Not Consider Map/Set/List Fields

    [ https://issues.apache.org/jira/browse/THRIFT-3703?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15174446#comment-15174446 ] 

Tom Deering commented on THRIFT-3703:
-------------------------------------

Seems to affect union fields of type map, set, and list.

> Unions Field Count Does Not Consider Map/Set/List Fields
> --------------------------------------------------------
>
>                 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
>              Labels: golang, thrift, union
>
> 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)