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:57:00 UTC

[jira] [Updated] (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:all-tabpanel ]

Роман Донченко updated GROOVY-8996:
-----------------------------------
    Description: 
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}

  was:
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}


> 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)