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

Incorrect closure owner inside anonymous inner class

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 2.4.3
    • None
    • Compiler
    • None

    Description

       abstract class A {
         private void m() {
          println 'm'
        }
          
        void wrong() {
          m()
          Closure c = {
            m()
          }
      
          c()
        }
      }
      
      class B {
        A a = new A() {}
        
        void b() {
         a.wrong()
       }
      }
      
      def b = new B()
      b.b()
      

      Produces the following error:

      groovy.lang.MissingMethodException: No signature of method: B.m() is applicable for argument types: () values: []
      Possible solutions: b(), is(java.lang.Object), dump(), any(), any(groovy.lang.Closure), use([Ljava.lang.Object;)
      	at B.this$dist$invoke$1(wrong.groovy)
      	at B$1.methodMissing(wrong.groovy)
      	at A.invokeMethod(wrong.groovy)
      	at A$_wrong_closure1.doCall(wrong.groovy:9)
      	at A$_wrong_closure1.doCall(wrong.groovy)
      	at A.wrong(wrong.groovy:12)
      	at A$wrong.call(Unknown Source)
      	at B.b(wrong.groovy:20)
      	at B$b.call(Unknown Source)
      	at wrong.run(wrong.groovy:25)
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              gcadien Geoff Cadien
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: