Groovy
  1. Groovy
  2. GROOVY-5989 Inner Class Issues
  3. GROOVY-4473

Cannot access outer class getter from inner class GString with property syntax

    Details

    • Type: Sub-task Sub-task
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.5
    • Fix Version/s: None
    • Component/s: groovy-runtime
    • Labels:
      None

      Description

      The following code...

      InnerClassGString.groovy:

      class Outer {  
        def foo() {
          def r = new Runnable() {
            public void run() {
              println "value of x is $x" // ${getX()} works, also $x with a field x
            }
          }       
          r.run()
        }  
        
        def getX() { 10 }     
      }         
      
      new Outer().foo()                    
      

      ...produces (when run via groovy command):

      Caught: groovy.lang.MissingFieldException: No such field: x for class: Outer
      	at Outer.this$dist$get$2(InnerClassGString.groovy)
      	at Outer$1.propertyMissing(InnerClassGString.groovy)
      	at Outer$1.run(InnerClassGString.groovy:5)
      	at Outer.foo(InnerClassGString.groovy:8)
      	at InnerClassGString.run(InnerClassGString.groovy:14)
      

        Activity

          People

          • Assignee:
            Guillaume Delcroix
            Reporter:
            Peter Niederwieser
          • Votes:
            4 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development