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

Traits, Force Override and generic types

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • None
    • None
    • Compiler

    Description

      The following works when run against the current master branch:

      import groovy.transform.*
      
      def a = [ 1, 2, 3, 4, 5 ]
      
      trait Doubler {
          @ForceOverride
          Object next() {
              super.next() * 2
          }
      }
      
      class ListIterator implements Iterator<Integer> {
          @Delegate Iterator<Integer> iter
          
          ListIterator( List<Integer> list ) {
              iter = list.iterator()
          }
      }
      
      assert new ListIterator( a ).withTraits( Doubler ).collect() == [ 2, 4, 6, 8, 10 ]
      

      But if you change the Doubler trait to the more correctly typed:

      trait Doubler {
          @ForceOverride
          Integer next() {
              super.next() * 2
          }
      }
      

      It isn't used, and the result is [1, 2, 3, 4, 5] instead.

      Not sure if this is a bug, or a gap in my understanding, but thought I'd put it here

      Attachments

        Activity

          People

            melix Cédric Champeau
            tim_yates Tim Yates
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: