[
https://issues.apache.org/jira/browse/GROOVY-11838?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Ayoub Ait Abdellah updated GROOVY-11838:
----------------------------------------
Labels: ast compiler (was: )
> 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
> Affects Versions: 5.0.0, 5.0.3
> Reporter: Ayoub Ait Abdellah
> Priority: Minor
> Labels: ast, compiler
> Fix For: 6.x
>
>
> 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
(v8.20.10#820010)