Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-5989 Inner Class Issues
  3. GROOVY-4473

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

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.5
    • None
    • groovy-runtime
    • 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)
      

      Attachments

        Activity

          People

            guillaume Guillaume Sauthier
            pniederw Peter Niederwieser
            Votes:
            4 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: