You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniel Sun (JIRA)" <ji...@apache.org> on 2019/02/17 03:44:00 UTC

[jira] [Commented] (GROOVY-8996) String literal unexpectedly resolving to a local variable

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

Daniel Sun commented on GROOVY-8996:
------------------------------------

I think it also exists in Groovy 2.5.6.
By looking into the code, I find method name with evaluating, i.e. GString method name is not resolved to local method. This kind of method is undefined, so delegated to the closure owner.
Note: the above logic is just my guess. I have not verified it. If  Groovy elders see the ticket, please confirm the logic.


> String literal unexpectedly resolving to a local variable
> ---------------------------------------------------------
>
>                 Key: GROOVY-8996
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8996
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 3.0.0-alpha-4
>            Reporter: Роман Донченко
>            Priority: Major
>
> Consider this code:
> {code:groovy}
> def toUpperCase = { 'ONE' }
> 'two'.with {
>     println toUpperCase()
>     println 'toUpperCase'()
>     println "${'toUpperCase'}"()
> }
> {code}
> It outputs this:
> {code}
> ONE
> ONE
> TWO
> {code}
> In other words, the argument to the second {{println}} is evaluated like the argument to the first one and not like the argument to the third one.
> This seems very surprising and wrong:
> # {{'toUpperCase'}} is equal to {{"${'toUpperCase'}"}}, so how can {{'toUpperCase'()}} and {{"${'toUpperCase'}"()}} be evaluated differently?
> # How can the string literal {{'toUpperCase'}} evaluate to the local variable {{toUpperCase}}? The documentation mentions using string literals for property and method names, but not for local variable names.
> In my opinion, the output should be:
> {code}
> ONE
> TWO
> TWO
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)