thrift-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chet Murthy <>
Subject Thrift unions don't work as documented
Date Fri, 01 Dec 2017 08:37:16 GMT
I dug into this question b/c I noticed that in plugin.thrift, the
t_const_value seemed to not be behaving as a union should.  To wit, it
seems that in the case of a type like

struct Foo {
  1: required Enum E x = E.A

(for some enum E), the t_const_value that represents the initializer, ends
up having both a "identifier_val" and an "enum_val".  And yet, in
plugin.thrift, it's a UNION.

So looking further, it seems that the (at least C++) code of a union, e.g.

union Bar {
  1: i32 a ;
  2: string b;

DOES NOT enforce the rule (from that

Unions are similar to structs, except that they provide a means to
transport exactly one field of a possible set of fields, just like union {}
in C++. Consequently, union members are implicitly considered optional (see

In no way, is there any enforcement of "exactly one field".

It seems to me that this needs fixing.  But it's a possibly- breaking

I can starting fixing it in C++, Python, Ocaml, and a few other languages.
Should I do so?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message