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

Closure in child class cannot access static method in parent class

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.3
    • Fix Version/s: 2.3.4
    • Component/s: None
    • Labels:
      None

      Description

      A regression affecting dynamic Groovy only (@CompileStatic code is not having this problem), a closure in a child class cannot call a static method in a parent class. This behavior was working at least as of 2.1.5.

      Closures of a subclass can no longer access static methods of a super class in 2.3.3 dynamic Groovy, while they could in 2.1.5. Adding @CompileStatic to the "fails" method below is one possible workaround. Another workaround is to call the method explicitly as SuperClass.f.

      class SuperClass {
              protected static f(String x) { x + " is super" }
      }
      
      class ChildClass extends SuperClass {
              public void doit() {
                      println works()
                      println fails()
              }
      
              private static def works() { f("Groovy") }
              private static def fails() { return {f("Groovy")}() }
      }
      
      new ChildClass().doit()
      

      Result is "groovy is super" and then on the fails method:
      groovy.lang.MissingMethodException: No signature of method: ChildClass$_fails_closure1.f() is applicable for argument types: (java.lang.String) values: [Groovy]
      Possible solutions: is(java.lang.Object), is(java.lang.Object), any(), find(), any(), find()

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                blackdrag Jochen Theodorou
                Reporter:
                gillius Jason Winnebeck
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: