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

Mark Slee commented on THRIFT-897:
----------------------------------

YIkes. I'll defer to whatever people prefer. Seems we can either:

(1) Require strongly-typed references to enums, as you propose
(2) Perform enum-lookups in a strongly-typed manner (i.e. when we see "const 
MyEnum", we know the only valid values are those in the MyEnum type)

The former seems cleaner/more-straightforward, but the latter is 
backwards-compatible.

> Don't allow unqualified constant access to enum values
> ------------------------------------------------------
>
>                 Key: THRIFT-897
>                 URL: https://issues.apache.org/jira/browse/THRIFT-897
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (General)
>    Affects Versions: 0.1, 0.2, 0.3, 0.4
>            Reporter: Bryan Duxbury
>             Fix For: 0.5
>
>
> Through looking at THRIFT-544 and THRIFT-895, it's come to my attention that 
> we currently register each of every enum's values as a global (and scoped) 
> constant. This allows you to do things like:
> {code}
> enum MyEnum {
>  A = 1
>  B = 2
> }
> const MyEnum myEnumVar = A;
> {code}
> This is handy, insofar as you might want to use the values of an enum in 
> constant or default circumstances. However, this behavior is unstable - if 
> you have two enums with values that have the same name, all constant 
> references will point at the last occurrence of the name. Further, in order 
> to allow this to go on, we must not check if any constant has been declared 
> twice, which means you can get stupid, detectable errors in your IDL very 
> easily.
> I propose that we stop allowing this method of access, and instead require 
> the enum values referenced in constant context to be prefixed with the enum 
> type's name. For instance:
> {code}
> enum MyEnum {
>  A = 1
>  B = 2
> }
> const MyEnum myEnumVar = MyEnum.A;
> {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