Enum validation fails when enum is defined in separate thrift file
See original GitHub issueWe noticed an error like this when running code gen:
E: 'One' is not a member of enum type Foo: members=[One]
with testing_foo.thrift
defined as:
namespace java testing
enum Foo {
One = 1
}
and testing_bar.thrift
defined as:
namespace java testing
include 'testing_foo.thrift'
struct Bar {
1: required testing_foo.Foo foo = Foo.One;
}
(This happens with required testing_foo.Foo foo = Foo.One
and required testing_foo.Foo foo = One
)
For reference required testing_foo.Foo foo = 1
seems to work fine.
It seems like the linking happens correctly, just the validation fails.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5
Top Results From Across the Web
Validate Thrift Enums with constant values
I have a Thrift file that specifies an enum as follows: enum MyEnumStuff { ABC = 7, ..., XYZ = 9, ..., //...
Read more >Thrift: The Missing Guide
Enums are specified C-style. Compiler assigns default values starting at 0. 2, You can of course, supply specific integral values for constants.
Read more >Validations for Enum Types
Learn how to build validations for enums using Java custom ... Let's start by defining an annotation to validate the pattern of an...
Read more >Chapter 6. Apache Thrift IDL - liveBook · Manning
In this chapter, we'll examine the features of the Apache Thrift Interface Definition Language (IDL) and learn how to use the Apache Thrift...
Read more >Apache Thrift - Interface Description Language (IDL)
The Thrift interface definition language (IDL) allows for the definition of ... [7] Definition ::= Const | Typedef | Enum | Struct |...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just confirmed my reading using the Apache compiler:
a.thrift:
b.thrift:
I’ll have a fix for the initial bug, but don’t want to deviate from Apache’s behavior more than necessary; we’ll match this validation behavior.
OK, I’ve finally got some time to address this. As I’m looking over the Apache compiler, it certainly appears that unqualified enum references in constants (e.g.
required testing_foo.Foo foo = One
) are not accepted; this is as of version 0.9.3. What version are you using that allows this?t_const_value.h
is approximately the same things as Thrifty’sConstValueElement
, and defines accessors used during const validation. The ones relevant to enums throw exceptions (i.e. fail) during const validation: https://github.com/apache/thrift/blob/0.9.3/compiler/cpp/src/parse/t_const_value.h#L107How was this working for you previously?