groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8369) Enum property access not working with @CompileStatic
Date Wed, 01 Nov 2017 07:15:00 GMT

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

ASF GitHub Bot commented on GROOVY-8369:
----------------------------------------

Github user paulk-asert commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/625#discussion_r148194617
  
    --- Diff: src/test/org/codehaus/groovy/classgen/asm/sc/FieldsAndPropertiesStaticCompileTest.groovy
---
    @@ -696,4 +696,21 @@ import org.codehaus.groovy.transform.sc.ListOfExpressionsExpression
                 assert astTrees['A$_closure1'][1].contains('INVOKESTATIC A.pfaccess$02 (LA;Ljava/lang/String;)Ljava/lang/String;')
             }
         }
    +
    +    //GROOVY-8369
    +    void testPropertyAccessOnEnumClass() {
    +        try {
    +            assertScript '''
    +                enum Foo {}
    +
    +                def test() {
    +                    println Foo.getModifiers() // => 16401 // ENUM | FINAL | PUBLIC
(see GROOVY_8360 wrt STATIC)
    +                    println Foo.modifiers      // java.lang.NoSuchFieldError: modifiers
    +                }    
    +                test()
    +            '''
    +        } finally {
    +            //println astTrees
    +        }
    +    }
    --- End diff --
    
    Perhaps a slight improvement to my original test would be comparing property access to
the getter result and also confirming that enum constants take preference over property access
(which worked before but I couldn't see covered in existing tests).
    ```
    @Deprecated
    enum Foo {
      annotations
    }
    
    @groovy.transform.CompileStatic
    def test() {
      assert 'annotations' == Foo.annotations.toString()
      assert Foo.getAnnotations().size() == 1
      assert Foo.getModifiers() == Foo.modifiers
    }
    
    test()
    ```


> Enum property access not working with @CompileStatic
> ----------------------------------------------------
>
>                 Key: GROOVY-8369
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8369
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.12
>            Reporter: Paul King
>            Assignee: Shil Sinha
>            Priority: Major
>
> {code}
> import groovy.transform.CompileStatic
> enum Foo { }
> @CompileStatic
> def test() {
>   println Foo.getModifiers() // => 16401 // ENUM | FINAL | PUBLIC (see GROOVY_8360
wrt STATIC)
>   println Foo.modifiers      // java.lang.NoSuchFieldError: modifiers
> }
> test()
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message