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

Stackable Traits at runtime don't honor definition order

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.7, 2.4.0
    • Fix Version/s: 2.3.10, 2.4.1
    • Component/s: groovy-runtime
    • Labels:
      None

      Description

      when defined at runtime, stackable traits don't honor the order in withTraits(), whereas when defined statically they do. see example code:

      trait D { 
              void methodA() { print "D"; super.methodA() } 
      } 
      trait C { 
              void methodA() { print "C"; super.methodA() } 
      } 
      trait B { 
              void methodA() { print "B"; super.methodA() } 
      } 
      trait A { 
              void methodA() { print "A" } 
      } 
      
      class M implements A, D, C, B { } 
      class Q {} 
      
      class MyDelegationTest { 
      
              static main(args) { 
                      
                      println "" ;
                      
                      def m = new M() ;
      
                      print "Static: " ;
      
                      m.methodA() ;
      
                      println "" ;
                      
                      def q = new Q().withTraits(A,D,C,B) ;
      
                      print "Dynamic: " ;
      
                      q.methodA() ;
      
                      println "" ;
      
              } 
      } 
      

      With output:

      (Correct Order) Static: BCDA

      (Incorrect Order) Dynamic: DCBA

        Attachments

          Activity

            People

            • Assignee:
              melix C├ędric Champeau
              Reporter:
              hadfield Marc Hadfield
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: