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 2022/07/06 22:52:00 UTC

[jira] [Comment Edited] (GROOVY-6025) Using short, byte, char annotation definition attribute constants should be supported

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

Eric Milles edited comment on GROOVY-6025 at 7/6/22 10:51 PM:
--------------------------------------------------------------

[~paulk] How important is "short s2() default (byte)3" or "short s4() default (int)5"?  I have fixes for 7252, 9205, 9206 and 9366 by moving the logic of {{AnnotationConstantVisitor}} into {{ExpressionUtils#transformInlineConstants(Expression,ClassNode)}}.  But the typecast handling is much simpler if it only needs to support no cast like "short s1() default 2" or same-type cast like "short s3() default (Short)4".

https://github.com/apache/groovy/commit/5fe6fbc7dfef4df52fff6cf96a95b6d46d4fbf3c


was (Author: emilles):
[~paulk] How important is "short s2() default (byte)3" or "short s4() default (int)5"?  I have fixes for 7252, 9205, 9206 and 9366 by moving the logic of {{AnnotationConstantVisitor}} into {{ExpressionUtils#transformInlineConstants(Expression,ClassNode)}}.  But the typecast handling is much simpler if it only needs to support no cast like "short s1() default 2" or same-type cast like "short s3() default (Short)4".

> Using short, byte, char annotation definition attribute constants should be supported
> -------------------------------------------------------------------------------------
>
>                 Key: GROOVY-6025
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6025
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.1.1
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>              Labels: annotations
>             Fix For: 2.1.2, 2.2.0-beta-1
>
>
> Currently this code:
> {code}
> import java.lang.annotation.*
> @Retention(RetentionPolicy.RUNTIME)
> @Target([ElementType.TYPE, ElementType.METHOD])
> public @interface Foo {
>     int i() default 3
>     short s() default 3
>     byte b() default 3
>     char c1() default 65
>     char c2() default 'A'
>     char c3() default (char)'A'
> }
> {code}
> generates compile time errors such as these:
> {noformat}
> 6 compilation errors:
> Attribute 's' should have type 'java.lang.Short'; but found type 'int' in @Foo
>  at line: 7, column: 23
> Attribute 'b' should have type 'java.lang.Byte'; but found type 'int' in @Foo
>  at line: 8, column: 22
> Attribute 'c1' should have type 'java.lang.Character'; but found type 'int' in @Foo
>  at line: 9, column: 23
> Attribute 'c2' should have type 'java.lang.Character'; but found type 'java.lang.String' in @Foo
>  at line: 10, column: 23
> expected '(char) A' to be an inline constant of type char in @Foo
>  at line: 11, column: 23
> Attribute 'c3' should have type 'java.lang.Character'; but found type 'java.lang.Object' in @Foo
>  at line: -1, column: -1
> {noformat}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)