[
https://issues.apache.org/jira/browse/GROOVY-11831?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18051368#comment-18051368
]
Paul King commented on GROOVY-11831:
------------------------------------
[~aaitabde] That would indeed be something we could look at. Changing the
private ALL_TARGETS variable in AnnotationNode (and perhaps renaming it to
DEFAULT_TARGETS) to remove those targets is perhaps enough to achieve what you
suggest. I did look at that as a potential alternative solution. It would
require further investigation to see whether any frameworks using Groovy are
relying on that. I suspect not but we would treat and advertise it as a
breaking change (so possibly Groovy 6 only).
Having said that, Groovy tries to give users additional flexibility in some
cases. We might, for instance, allow a DSL to have TYPE_USE annotations on a
void method in early compiler phases so long as there are AST transforms that
remove it before class generation. But we don't drift away from the JLS (even
just for early compilation phases) unless we have a good reason. I don't know
of any frameworks that would need the extra flexibility at this point, so we
might tighten up that part of the compiler in any case for Groovy 6.
In terms of timing, one thing I was thinking of is that we hope to add for
Groovy 6, annotations in more places, e.g. as a potential example, we could
allow an @Invariant annotation on a for loop. That would allow design by
contract loop assertion statements to be added by the groovy-contracts
transforms. We would not keep the annotations at runtime since there is no JVM
support. So my thinking is we can delay thinking about tightening annotation
rules until we make further decisions about how we'd support annotations in
more places. Feel free to create a separate issue if you want to help us not
forget that aspect. We might just not proceed for a while.
> Compiler crash with TYPE_USE annotation on void method during AST
> transformation
> --------------------------------------------------------------------------------
>
> Key: GROOVY-11831
> URL: https://issues.apache.org/jira/browse/GROOVY-11831
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 5.0.0, 5.0.3
> Reporter: Ayoub Ait Abdellah
> Assignee: Paul King
> Priority: Blocker
> Labels: ast, compiler
> Fix For: 6.0.0-alpha-1, 5.0.4
>
>
> h2. Summary
> Groovy 5 compiler crashes during class generation when an AST transformation
> adds an annotation (without explicit {{{}@Target{}}}) to a method that
> returns {{{}void{}}}.
> h2. Error Message
> {code:java}
> BUG! exception in phase 'class generation' in source unit '...'
> Adding type annotation @MyAnnotation to non-redirect node: void
> {code}
> h2. Affected Versions
> Tested and confirmed on 5.0.0 and 5.0.3 (latest). Bug is present in all
> Groovy 5.x releases.
> h2. Minimal Reproduction
> {code:bash}
> git clone https://github.com/ayoube-ait/groovy-bug-repro.git
> cd groovy-bug-repro
> ./gradlew clean :groovy-app:compileGroovy
> {code}
> Repository: [https://github.com/ayoube-ait/groovy-bug-repro]
> h2. Root Cause
> # An annotation is defined without explicit {{@Target}} (defaults to all
> targets including {{{}TYPE_USE{}}})
> # An AST transformation creates a method with {{ClassHelper.VOID_TYPE}}
> return type
> # The transformation adds the annotation to this void method
> # During class generation, {{ExtendedVerifier.extractTypeUseAnnotations()}}
> attempts to process the annotation as {{TYPE_USE}}
> # It tries to call {{addTypeAnnotations()}} on the {{void}} return type
> # {{void}} is a "non-redirect node" causing the crash
> h2. Expected Behavior
> The compiler should skip TYPE_USE annotation processing for {{void}} return
> types instead of crashing.
> h2. Related Issues
> GROOVY-11479 - Similar crash with TYPE_USE annotations on lambda parameters
> (fixed in 5.0.0-alpha-11). That fix addressed lambda parameters but not void
> return types in AST-generated methods.
> h2. Impact
> This bug affects Micronaut Framework's Groovy support. The {{@Internal}}
> annotation in micronaut-core has no explicit {{@Target}} and is used in AST
> transformations that generate void methods, preventing Groovy function
> scripts from compiling with Micronaut 5 + Groovy 5.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)