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

David Reiss commented on THRIFT-544:
------------------------------------

I think the patch is correct, but the argument for correctness is very 
complicated because constants_[name] is a mutating operation that creates an 
entry if the "name" key is not present.  I'd much prefer the condition be 
"constants_.find(name) != constants.end()"

> multiple enums with the same key generate invalid code
> ------------------------------------------------------
>
>                 Key: THRIFT-544
>                 URL: https://issues.apache.org/jira/browse/THRIFT-544
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (General)
>    Affects Versions: 0.1
>            Reporter: Ben Taitelbaum
>            Priority: Minor
>             Fix For: 0.1
>
>         Attachments: thrift-544_add_enum_name_to_enum_keys.patch, 
> thrift-544_prevent_redefining_consts.patch
>
>
> The current generator produces multiple -define statements with the same 
> name, which isn't valid erlang code (and also isn't valid semantically if we 
> want two different values).
> {code:title=EnumTest.thrift|borderStyle=solid}
> enum MyType1 {
>   A = 0,
>   B = 1
> }
> enum MyType2 {
>   A = 2,
>   C = 4
> }
> {code}
> produces:
> {code:title=enumTest_types.hrl|borderStyle=solid}
> -ifndef(_enumTest_types_included).
> -define(_enumTest_types_included, yeah).
> -define(enumTest_A, 0).
> -define(enumTest_B, 1).
> -define(enumTest_A, 2).
> -define(enumTest_C, 4).
> -endif.
> {code}
> In the patched version, it produces this:
> {code:title=enumTest_types.hrl|borderStyle=solid}
> -ifndef(_enumTest_types_included).
> -define(_enumTest_types_included, yeah).
> -define(enumTest_MyType1_A, 0).
> -define(enumTest_MyType1_B, 1).
> -define(enumTest_MyType2_A, 2).
> -define(enumTest_MyType2_C, 4).
> -endif.
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to