Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8996

String literal unexpectedly resolving to a local variable

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.0.0-alpha-4
    • Fix Version/s: None
    • Component/s: Compiler
    • Labels:
      None

      Description

      Consider this code:

      def toUpperCase = { 'ONE' }
      
      'two'.with {
          println toUpperCase()
          println 'toUpperCase'()
          println "${'toUpperCase'}"()
      }
      

      It outputs this:

      ONE
      ONE
      TWO
      

      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:

      ONE
      TWO
      TWO
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              dpb Роман Донченко
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: