groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Sun (Jira)" <j...@apache.org>
Subject [jira] [Comment Edited] (GROOVY-8444) Support unqualified enum constants in switch cases (like Java)
Date Sat, 26 Oct 2019 08:17:00 GMT

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

Daniel Sun edited comment on GROOVY-8444 at 10/26/19 8:16 AM:
--------------------------------------------------------------

For dynamic groovy, it's much harder to implement such a feature, as its type info is detected
at runtime. So we need generate much more complicated bytecode to pass the condition expression
to the expression in case statement, in the meanwhile, the condition expression can not be
evaluated multi-times to avoid side effect, i.e. we should save the evaluated result first...

P.S. Using {{@TypeChecked}} will take effect too.


was (Author: daniel_sun):
For dynamic groovy, it's much harder to implement such a feature, as its type info is detected
at runtime. So we need generate much more complicated bytecode to pass the condition expression
to the expression in case statement, in the meanwhile, the condition expression can not be
evaluated multi-times to avoid side effect...

P.S. Using {{@TypeChecked}} will take effect too.

> Support unqualified enum constants in switch cases (like Java)
> --------------------------------------------------------------
>
>                 Key: GROOVY-8444
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8444
>             Project: Groovy
>          Issue Type: Improvement
>          Components: Static compilation
>            Reporter: Eric Milles
>            Assignee: Daniel Sun
>            Priority: Major
>             Fix For: 3.0.0-rc-1
>
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> Would it be possible to support this syntax that Java requires for enum constants in
switch statements?
> {code:java}
> enum SomeEnum { A, B }
> void meth(SomeEnum e) {
>   switch (e) {
>   case A: // currently this must be qualified, like SomeEnum.A
>     ...
>     break
>   case B:
>     ...
>     break
>   }
> }
> meth(someEnumValue) // currently throws MissingPropertyException: No such property: A
for class...
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Mime
View raw message