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

Matteo Fiandesio commented on GROOVY-11838:
-------------------------------------------

This also fixes GROOVY-12787 on 5.x: several @MapConstructor classes in one 
compilation get duplicate @NamedParams type annotations on their Map 
constructor (AnnotationFormatError when reflected on, and the reported 
@NamedParams lists another class's parameters). The commit cherry-picks onto 
GROOVY_5_1_X with a formatting-only conflict, and the details and test results 
for a 5.1.x backport are there.

> Make default annotation targets follow JLS 9.6.4.1 (exclude TYPE_USE and 
> TYPE_PARAMETER)
> ----------------------------------------------------------------------------------------
>
>                 Key: GROOVY-11838
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11838
>             Project: Groovy
>          Issue Type: Improvement
>          Components: Compiler
>            Reporter: Ayoub Ait Abdellah
>            Assignee: Eric Milles
>            Priority: Minor
>              Labels: annotations, ast, compiler
>             Fix For: 6.0.0-alpha-1
>
>
> h2. Summary
> Annotations without explicit @Target should default to all declaration 
> contexts and no type contexts, per JLS 9.6.4.1.
> h2. Background
> Currently, Groovy treats annotations without @Target as applicable to all 
> targets including TYPE_USE and TYPE_PARAMETER. This violates JLS 9.6.4.1:
> {quote}If an annotation of type java.lang.annotation.Target is not present on 
> the declaration of an annotation interface A, then A is applicable in all 
> declaration contexts and in no type contexts.
> {quote}
> h2. Proposed Change
> In {{{}AnnotationNode.java{}}}, change the default {{allowedTargets}} from 
> {{ALL_TARGETS}} to declaration contexts only:
> {code:java}
> private static final int DECLARATION_TARGETS = TYPE_TARGET | 
> CONSTRUCTOR_TARGET | METHOD_TARGET
>         | FIELD_TARGET | PARAMETER_TARGET | LOCAL_VARIABLE_TARGET | 
> ANNOTATION_TARGET
>         | PACKAGE_TARGET | RECORD_COMPONENT_TARGET;
> private int allowedTargets = DECLARATION_TARGETS;  // was ALL_TARGETS
> {code}
> h2. Related
>  * GROOVY-11831 - Compiler crash that led to this investigation (fixed with a 
> guard for void methods)
>  * [JLS 
> 9.6.4.1|https://docs.oracle.com/javase/specs/jls/se21/html/jls-9.html#jls-9.6.4.1]
> h2. Note
> As discussed in GROOVY-11831, this is a breaking change suitable for Groovy 6.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to