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 2020/12/21 17:01:00 UTC

[jira] [Commented] (GROOVY-9855) Compiler does not resolve compile-time constants in string concatenation

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

Eric Milles commented on GROOVY-9855:
-------------------------------------

There is some inline transformation of constants done by {{ResolveVisitor}}.  Later on, {{AnnotationVisitor}} runs and is where most of the compile-time combination of numbers and strings is done.  Static Compilation runs {{}} between the two and this is what is turning "ConfigProps.PREFIX + '.suffix'" into "'prefix'.plus('.suffix')", which is not recognized by {{AnnotationVisitor}} and left as-is.

The pull request addresses string concat only.  This issue likely still exists for numbers and mixed strings and numbers.

> Compiler does not resolve compile-time constants in string concatenation
> ------------------------------------------------------------------------
>
>                 Key: GROOVY-9855
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9855
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler, Static compilation
>    Affects Versions: 3.0.7
>            Reporter: Christopher Smith
>            Assignee: Eric Milles
>            Priority: Minor
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> {code:groovy}
> @Qualifier(ConfigProps.PREFIX + '.suffix')
> @CompileStatic
> class ConfigProps {
>     public static final String PREFIX = 'prefix'
> }
> {code}
> In this case, the value ({{prefix.suffix}}) is a compile-time constant and should be available as an annotation parameter, but the compiler does not recognize this. Both plain and static compilation produce errors, though different errors:
> dynamic:
> {code}
> The value for annotation attribute Qualifier.value must be a constant expression
> {code}
> static:
> {code}
> Attribute 'value' should have type 'java.lang.String'; but found type 'java.lang.Object'
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)