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

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

ayoube-ait opened a new pull request, #2362:
URL: https://github.com/apache/groovy/pull/2362

    ## GROOVY-11831: Fix TYPE_USE annotation crash on void method return type
   
     ### Summary
   
     Fixes a compiler crash when an annotation without explicit `@Target` 
(which defaults to all targets including `TYPE_USE`) is added to a void method 
by an AST transformation.
   
     ### Error Message
   
     BUG! exception in phase 'class generation' in source unit '...'
     Adding type annotation @MyAnnotation to non-redirect node: void
   
     ### Root Cause
   
     In `ExtendedVerifier.extractTypeUseAnnotations()`, when processing 
TYPE_USE annotations on a void method, the code attempts to call 
`addTypeAnnotations()` on the void return type. Since `void` is a non-redirect 
node, this crashes.
   
     ### Fix
   
     Added a guard to skip `addTypeAnnotations()` for void methods only:
   
     ```java
     boolean isVoidMethod = (keepTarget == METHOD_TARGET && 
isPrimitiveVoid(targetType));
     if (!isVoidMethod) {
         // ... add type annotations
     }
   
     The fix specifically targets void methods, not constructors (which also 
have void return type internally but are handled differently via GROOVY-10937).
   ```
   
     ### Testing
   
     A unit test is not included because the bug only triggers when:
     1. The annotation is pre-compiled in a separate JAR (not defined inline)
     2. An AST transformation adds that annotation to a void method
   
     Groovy's test framework compiles everything in one stage, making it 
impossible to reproduce this scenario in a single test.
   
     Manual verification: The fix is verified with a standalone reproduction 
project:
     https://github.com/ayoube-ait/groovy-bug-repro
   
     ### 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 scripts from 
compiling with Micronaut 5 and Groovy 5.
   
   
   




> 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
>            Priority: Blocker
>              Labels: ast, compiler
>
> 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)

Reply via email to