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 2019/11/29 19:41: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=16985183#comment-16985183 ] 

Eric Milles commented on GROOVY-8996:
-------------------------------------

I would expect that 
{code:groovy}
"two".with { println toUpperCase() }
{code}
to output "TWO" no matter what local variables, parameters or other surrounding elements exist.  The DGM {{with}} states that the delegate is the first choice for resolving implicit-this expressions like method calls.

> 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
(v8.3.4#803005)