[ 
https://issues.apache.org/jira/browse/THRIFT-1318?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Jens Geyer updated THRIFT-1318:
-------------------------------

    Attachment: 
THRIFT-1318_Incorrect_syntax_for_struct_with_enum_property_and_default_value_when_value_is_negative_rev2.patch

I had some difficulties applying your old SVN patch. I finally came up with 
this solution which is IMHO much better, as it makes more sense to write the 
assignments as 

{code}
this.property = MyEnumType.SomeValue;
{code}

instead of the C-ish casting style like

{code}
this.property = (MyEnumType)(-42);
{code}

And since it seems not to be possible to assign values other than the 
IDL-defined enum values, there is no reason left to use the cast.
                
> Incorrect syntax for struct with enum property and default value when value 
> is negative
> ---------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1318
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1318
>             Project: Thrift
>          Issue Type: Bug
>          Components: C# - Compiler
>    Affects Versions: 0.7
>         Environment: Windows 7 / .net 4.0
>            Reporter: Thunder Stumpges
>         Attachments: NegativeEnumConstant.patch, 
> THRIFT-1318_Incorrect_syntax_for_struct_with_enum_property_and_default_value_when_value_is_negative_rev2.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> If I have a struct with a property of type enum with a default value 
> specified, and the default value is negative, then the code generated is 
> incorrect and has a syntax error.
> E.G. thrift file like this:
> {code}
> enum ReturnType {
>     SuccessTypeA = 2
>     SuccessUnknownType = 1,
>     FailUnknown = -1,
>     OtherFailure = -2
> }
> struct ReturnInformation {
>       1: required ReturnType RetType = ReturnType.FailUnknown;
> }
> {code}
> Generates a constructor like this:
> {code}
>     public MatchInformation() {
>       this._MatchType = (MatchTypes)-1;
>     }
> {code}
> which fails with an exception "To cast a negative value, you must enclose the 
> value in parentheses".
> I have updated the code to always put the enum constant value in parentheses 
> (positive or negative), but need to get the compiler built and tested before 
> I can submit a patch. Any chance someone could do this for me?
> :)
>  

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to