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

Paul King commented on GROOVY-11614:
------------------------------------

As per GROOVY-8444, the enum type can be elided when TypeChecked/CompileStatic 
is used,
but it seems like switch statements only and not switch expressions currently:
{code}
enum Letter { A, B, C, D }

@groovy.transform.TypeChecked
def method(Letter x) {
    switch(x) {
        case A: println 'a'; break
        case B: println 'b'; break
        default:
            println switch(x) {
                case C -> 'c'
                case D -> 'd'
            }
    }
}

method(Letter.A)
method(Letter.B)
method(Letter.C)
{code}

{noformat}
a
b
Exception thrown
groovy.lang.MissingPropertyException: No such property: C
{noformat}



> Enums in switch/case statements that are not fully qualified will cause a 
> groovy compile error but Java requires enums to "not" be fully qualified
> --------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-11614
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11614
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 4.0.24
>            Reporter: Saravanan
>            Priority: Minor
>
> This is a difference in Java vs Groovy behaviour. Enums must be fully 
> qualified in Groovy while Java requires them to not be fully qualified.
> -This was supposedly fixed, but does not seem to work in 4.0.24. Not sure 
> where it broke.-
> Example:
> {code:groovy}
> void test(Thread.State ts) {
>   switch (ts) {
>     case Thread.State.NEW: // cannot remove "Thread.State." without 
> @CompileStatic
>       break
>   }
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to