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

Calling parents method from trait using Parent.super.method() fail depending on trait declaration order

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.4.7
    • 2.4.10
    • Compiler
    • Grails 3.1.9

    Description

      I'm using trait for multiple inheritance and I faced an issue when compiling my project (using Grails 3.1.9, so with the gradle task CompileGroovy).
      My traits are sharing a common method (def method()) and I'm referencing parent's version through ParentClassName.super.method()

      I'm seeing this error:

      > BUG! exception in phase 'semantic analysis' in source unit 'xxx.groovy' ClassNode#getTypeClass for YYY is called before the type class is set

      When testing different cases it seems that this problem appears because classes are not compiled in the right order.

      For example, a script with

      trait Three implements One, Two {
          def postMake() {
              One.super.postMake()
              Two.super.postMake()
              println "Three"
          }
      }
      trait One {
          def postMake() { println "One"}
      }
      trait Two {
          def postMake() { println "Two"}
      }
      class Four implements Three {
          def make() {
              Three.super.postMake()
              println "All done?"
          }
      }
      Four f = new Four()
      f.make()
      

      will fail, whereas putting Three method after One and Two will succeed.
      Beside, keeping this trait's declaration order but changing method names to be unique (and removing XXX.super) will compile and execute correctly.

      I hope I'm clear enough...

      Attachments

        Activity

          People

            paulk Paul King
            sebcworks Sébastien Collin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: