You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Bryan Duxbury (JIRA)" <ji...@apache.org> on 2010/09/10 20:59:34 UTC

[jira] Created: (THRIFT-897) Don't allow unqualified constant access to enum values

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.4, 0.3, 0.2, 0.1
            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.


[jira] Updated: (THRIFT-897) Don't allow unqualified constant access to enum values

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-897?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryan Duxbury updated THRIFT-897:
---------------------------------

    Attachment: thrift-897.patch

This patch enforces fully qualified enum value references. 

> 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
>
>         Attachments: thrift-897.patch
>
>
> 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.


[jira] Commented: (THRIFT-897) Don't allow unqualified constant access to enum values

Posted by "David Reiss (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-897?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12908151#action_12908151 ] 

David Reiss commented on THRIFT-897:
------------------------------------

I think this is a really simple change, but it will break existing files.

> 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.


[jira] Commented: (THRIFT-897) Don't allow unqualified constant access to enum values

Posted by "Mark Slee (JIRA)" <ji...@apache.org>.
    [ 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.


[jira] Closed: (THRIFT-897) Don't allow unqualified constant access to enum values

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-897?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryan Duxbury closed THRIFT-897.
--------------------------------

    Resolution: Fixed

I just committed this.

> 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
>            Assignee: Bryan Duxbury
>             Fix For: 0.5
>
>         Attachments: thrift-897.patch
>
>
> 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.


[jira] Commented: (THRIFT-897) Don't allow unqualified constant access to enum values

Posted by "David Reiss (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-897?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12908393#action_12908393 ] 

David Reiss commented on THRIFT-897:
------------------------------------

LGTM.  In the main.cc part, you could possibly check the part before the dot matches the name of the enum (possibly with the scope qualifier).  Not critical.

> 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
>            Assignee: Bryan Duxbury
>             Fix For: 0.5
>
>         Attachments: thrift-897.patch
>
>
> 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.


[jira] Issue Comment Edited: (THRIFT-897) Don't allow unqualified constant access to enum values

Posted by "Jeff DeCew (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-897?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12908172#action_12908172 ] 

Jeff DeCew edited comment on THRIFT-897 at 9/10/10 4:24 PM:
------------------------------------------------------------

What would be the cost of doing type resolution?  I think this might be the most convenient (and backward-compatible) behavior, but I have no idea if it is feasible in the current architecture of the compiler.

This is my proposal:

{code}
enum MyEnum {
 A = 1
 X = 2
}
enum OtherEnum {
 B = 1
 X = 2
}

// Automatically resolve A to MyEnum.A and allow to compile
const MyEnum myConst1 = A;

// Automatically resolve B to MyEnum.B and FAIL to compile because MyEnum.B does not exist
const MyEnum myConst2 = B;

// Allow to compile
const MyEnum myConst3 = OtherEnum.B;

// Allow to compile
const MyEnum myConst4 = MyEnum.A;

// Automatically resolve X to MyEnum.X and allow to compile (but maybe warn that X was ambiguously resolved)
const MyEnum myConst5 = X;

// Can't automatically resolve A (even though it is unique), FAIL to compile
const i32 myConst6 = A;
{code}


      was (Author: jdecew):
    What would be the cost of doing type resolution?  I think this might be the most convenient (and backward-compatible) behavior, but I have no idea if it is feasible in the current architecture of the compiler.

This is my proposal:

{code}
enum MyEnum {
 A = 1
 X = 2
}
enum OtherEnum {
 B = 1
 X = 2
}

// Automatically resolve A to MyEnum.A and allow to compile
const MyEnum myConst1 = A;

// Automatically resolve B to MyEnum.B and FAIL to compile because MyEnum.B does not exist
const MyEnum myConst2 = B;

// Allow to compile
const MyEnum myConst3 = OtherEnum.B;

// Allow to compile
const MyEnum myConst4 = MyEnum.A;

// Automatically resolve X to MyEnum.X and allow to compile (but maybe warn that X was ambiguously resolved)
const MyEnum myConst5 = X;
{code}

  
> 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.


[jira] Commented: (THRIFT-897) Don't allow unqualified constant access to enum values

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-897?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12908188#action_12908188 ] 

Bryan Duxbury commented on THRIFT-897:
--------------------------------------

I think the smart resolution thing is only worthwhile if we really want to keep backwards compatibility. I'm not crazy about breaking people's IDL, but I think that's preferable in the long term to supporting a more convoluted syntax.

If we were starting from scratch today, I think that we'd want to use the fully-qualified approach, and the cost of fixing the breakage *should* be reasonably low, especially because you're getting a consistency improvement at the same time. This is certainly my preference.

> 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.


[jira] Commented: (THRIFT-897) Don't allow unqualified constant access to enum values

Posted by "Jeff DeCew (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-897?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12908172#action_12908172 ] 

Jeff DeCew commented on THRIFT-897:
-----------------------------------

What would be the cost of doing type resolution?  I think this might be the most convenient (and backward-compatible) behavior, but I have no idea if it is feasible in the current architecture of the compiler.

This is my proposal:

{code}
enum MyEnum {
 A = 1
 Z = 2
}
enum OtherEnum {
 B = 1
 Z = 2
}

// Automatically resolve A to MyEnum.A and allow to compile
const MyEnum myConst1 = A;

// Automatically resolve B to MyEnum.B and FAIL to compile because MyEnum.B does not exist
const MyEnum myConst2 = B;

// Allow to compile
const MyEnum myConst3 = OtherEnum.B;

// Allow to compile
const MyEnum myConst4 = MyEnum.A;

// Automatically resolve X to MyEnum.X and allow to compile (but maybe warn that X was ambiguously resolved)
const MyEnum myConst5 = X;
{code}


> 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.


[jira] Updated: (THRIFT-897) Don't allow unqualified constant access to enum values

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-897?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryan Duxbury updated THRIFT-897:
---------------------------------

      Assignee: Bryan Duxbury
    Patch Info: [Patch Available]

> 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
>            Assignee: Bryan Duxbury
>             Fix For: 0.5
>
>         Attachments: thrift-897.patch
>
>
> 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.


[jira] Issue Comment Edited: (THRIFT-897) Don't allow unqualified constant access to enum values

Posted by "Jeff DeCew (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-897?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12908172#action_12908172 ] 

Jeff DeCew edited comment on THRIFT-897 at 9/10/10 4:21 PM:
------------------------------------------------------------

What would be the cost of doing type resolution?  I think this might be the most convenient (and backward-compatible) behavior, but I have no idea if it is feasible in the current architecture of the compiler.

This is my proposal:

{code}
enum MyEnum {
 A = 1
 X = 2
}
enum OtherEnum {
 B = 1
 X = 2
}

// Automatically resolve A to MyEnum.A and allow to compile
const MyEnum myConst1 = A;

// Automatically resolve B to MyEnum.B and FAIL to compile because MyEnum.B does not exist
const MyEnum myConst2 = B;

// Allow to compile
const MyEnum myConst3 = OtherEnum.B;

// Allow to compile
const MyEnum myConst4 = MyEnum.A;

// Automatically resolve X to MyEnum.X and allow to compile (but maybe warn that X was ambiguously resolved)
const MyEnum myConst5 = X;
{code}


      was (Author: jdecew):
    What would be the cost of doing type resolution?  I think this might be the most convenient (and backward-compatible) behavior, but I have no idea if it is feasible in the current architecture of the compiler.

This is my proposal:

{code}
enum MyEnum {
 A = 1
 Z = 2
}
enum OtherEnum {
 B = 1
 Z = 2
}

// Automatically resolve A to MyEnum.A and allow to compile
const MyEnum myConst1 = A;

// Automatically resolve B to MyEnum.B and FAIL to compile because MyEnum.B does not exist
const MyEnum myConst2 = B;

// Allow to compile
const MyEnum myConst3 = OtherEnum.B;

// Allow to compile
const MyEnum myConst4 = MyEnum.A;

// Automatically resolve X to MyEnum.X and allow to compile (but maybe warn that X was ambiguously resolved)
const MyEnum myConst5 = X;
{code}

  
> 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.


[jira] Commented: (THRIFT-897) Don't allow unqualified constant access to enum values

Posted by "David Reiss (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-897?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12908177#action_12908177 ] 

David Reiss commented on THRIFT-897:
------------------------------------

For simple constants like the ones in your example, I think it would be reasonably easy.  For things like container and structure contants containing enums, it would be harder.

> 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.