You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2020/09/09 15:56:00 UTC

[jira] [Commented] (GROOVY-9723) CLONE - ASTTest annotation has runtime retention and transform removes required member from AST

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

Eric Milles commented on GROOVY-9723:
-------------------------------------

You could drop the runtime retention part of the issue; keeping the annotation in the class file and runtime state does not impact function, only efficiency.  Removing the closure expression from the AST is the main problem.

I never did figure out why Groovy's gradle build has no issue with the ASTTest annotations and Groovy-Eclipse's compilation sequence does.  Easiest thing from my end was to just add something back to the AST to satisfy the required annotation attribute.

> CLONE - ASTTest annotation has runtime retention and transform removes required member from AST
> -----------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-9723
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9723
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Major
>
> Description below is for GROOVY-9702 which is fixed in master. This issue is to explore a partial non-breaking fix for Groovy 3 (and maybe 2.5).
> =============
> Consider the following:
> {code:groovy}
> import groovy.transform.*
> import org.codehaus.groovy.ast.*
> import static org.codehaus.groovy.transform.stc.StaticTypesMarker.*
> class C {
>   void m() {
>     def that = this;
>     { ->
>       @ASTTest(phase=INSTRUCTION_SELECTION, value={
>         ClassNode type = node.getNodeMetaData(INFERRED_TYPE)
>         assert type?.name == 'C'
>       })
>       def ref = getThisObject()
>       assert ref == that
>     }()
>   }
> }
> {code}
> This is a typical use of {{@ASTTest}}.  When compiled, the test annotation is retained in the class file, which is unnecessary.  When the transform class runs, it removes the "value" member from the AST, which is causing compiler errors down the line when {{ExtendedVerifier}} runs {{AnnotationVisitor}}.  Also, the variable scope of the test closure is still connected to the class and module, so code completion is making proposals for class members which will not be there at run-time.
> This was originally investigated from the IDE side (see linked issue).
> [https://user-images.githubusercontent.com/18193802/90964420-fd51c800-e485-11ea-8349-c0f89e04561a.png]



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