You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Роман Донченко (JIRA)" <ji...@apache.org> on 2019/02/17 00:56:00 UTC

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

Роман Донченко created GROOVY-8996:
--------------------------------------

             Summary: 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: Роман Донченко


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:

1. {{'toUpperCase'}} is equal to {{"${'toUpperCase'}"}}, so how can {{'toUpperCase'()}} and {{"${'toUpperCase'}"()}} be evaluated differently?
2. 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)