You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2017/02/17 10:45:42 UTC

[jira] [Commented] (GROOVY-7402) Compiler NPE Related To AST Transformations And Traits

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

Paul King commented on GROOVY-7402:
-----------------------------------

This turns out to be separate from GROOVY-8066 and GROOVY-8048. It is triggered by having @Immutable on the trait and we don't support most AST transforms (including @Immutable) in conjunction with traits. We can step around the NPE fairly easily but then the current behavior for annotations on traits kicks in which is to copy any annotations from the trait to the trait helper class. The issue then is that in this case, the abstract helper class is made final by @Immutable and a class can't be both abstract and final. The compiler has checks for such illegal modifier combinations but they aren't currently run on generated classes.

We could re-jig the annotation copying behavior to make this case work but it would probably break other cases.

We can in the short-term catch some of these errors and produce compiler warnings.

A more general solution would be to have a mechanism to specify where annotations on the trait might be targeted: on the trait itself, a class implementing a trait, the helper or field helper etc. but that is a bigger piece of work.

> Compiler NPE Related To AST Transformations And Traits
> ------------------------------------------------------
>
>                 Key: GROOVY-7402
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7402
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.4.3
>            Reporter: Jeff Scott Brown
>         Attachments: traitannotation.zip
>
>
> Related to https://github.com/grails/grails-core/issues/663.
> The attached traitannotation.zip includes the following:
> {code:title=src/main/groovy/demo/SomeTrait.groovy|borderStyle=solid}
> package demo
> import groovy.transform.*
> @Immutable
> trait SomeTrait {
>     String name
> }
> {code}
> {code:title=src/main/groovy/demo/SomeClass.groovy|borderStyle=solid}
> package demo
> class SomeClass implements SomeTrait {}
> {code}
> Compilation raises an NPE:
> {noformat}
> $ ./gradlew clean cG
> :clean
> :compileJava UP-TO-DATE
> :compileGroovy FAILED
> FAILURE: Build failed with an exception.
> * What went wrong:
> Execution failed for task ':compileGroovy'.
> > BUG! exception in phase 'instruction selection' in source unit '/Users/jeff/traitannotation/src/main/groovy/demo/SomeTrait.groovy' unexpected NullpointerException
> * Try:
> Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
> BUILD FAILED
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)