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

Jens Geyer commented on THRIFT-5540:
------------------------------------

The problem is the way how symbolic constants, particularly enums, are (not) 
resolved.

The parsing code actually does indeed call {{{}const_value.set_enum(){}}}. 
which sets up the connection between the reference and the underlying type, but 
it's way too late and therefore essentially only sets the value for the 
constant of the previous pass. The second pass references never get resolved, 
but these are used when the actual integer value is fetched, usually during 
{{{}generate_const(){}}}. That call is made differently in the various 
generators, so some are running into that trap and some don't.

The patch fixes the references before entering generation state (and also fixes 
a typedef dereference issue).

> Can't use a typedef for a container type containing enums in a constant
> -----------------------------------------------------------------------
>
>                 Key: THRIFT-5540
>                 URL: https://issues.apache.org/jira/browse/THRIFT-5540
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (General)
>    Affects Versions: 0.16.0
>            Reporter: Raymond Chee
>            Assignee: Jens Geyer
>            Priority: Minor
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> This small thrift file fails to compile.
> {code:java}
> enum SomeEnum {
>     A,
>     B,
>     C
> }
> typedef map<SomeEnum, i32> SomeMap
> const SomeMap MY_MAP = {
>     SomeEnum.A: 123,
>     SomeEnum.B: 456,
>     SomeEnum.C: 789
> }
>  {code}
> Trying to compile this thrift file results in this error: 
> {code:java}
> [FAILURE:generation:1] Error: have identifier "SomeEnum.A", but unset enum on 
> line!{code}
>  
> If I didn't use the typedef and instead declared MY_MAP with type 
> map<SomeEnum, i32>, there is no issues with compilation. This issue also 
> happens if SomeEnum is the value type in the map, and it also happens for 
> typedefs of lists of enums.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to