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

ClassNode getField(String), getMethods(String) and others return from super interface when class uses extends

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 5.0.0-alpha-6
    • None

    Description

      Consider the following:

      trait A {
        def m() {}
      }
      trait B extends A {
      }
      

      Calling ClassNode#getMehtod(String) before the canonicalization compile phase returns "m()". Normally a super-trait or super-interface method would not be returned – when appearing in the implements clause for example.

      The test cases of GROOVY-8272 and GROOVY-10312 are examples of where this comes up.

      trait A {
        static sm() {
          'A'
        }
      }
      trait B extends A {
        String m() {
          sm().toLowerCase()
        }
      }
      class C implements B {
      }
      print(new C().m())
      

      StaticImportVisitor runs during semantic analysis before the trait transform has moved A from super class to super interface. Asking for the methods "sm" of B returns the method of A and so "sm()" is transformed into the static call "B.sm()". Leaving the method call unchanged allows it to be resolved through other trait means and fixes 8272, 10312 without dynamic dispatch (of trait helpers) that was added in Groovy 5.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              emilles Eric Milles
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: