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

Problem With Trait Generics

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.7
    • 4.0.0-alpha-1, 3.0.6
    • None
    • None

    Description

      The project at https://github.com/jeffbrown/generictraits contains the following:

      src/main/groovy/demo/TopTrait.groovy
      package demo
      
      trait TopTrait<T> {
          T getSomething() {}
      }
      
      src/main/groovy/demo/MiddleTrait.groovy
      package demo
      
      trait MiddleTrait<T> implements TopTrait<T> {}
      
      src/main/groovy/demo/BottomTrait.groovy
      package demo
      
      trait BottomTrait<T> implements MiddleTrait<T> {}
      
      src/main/groovy/demo/Demo.groovy
      package demo
      
      // if this class implements MiddleTrait instead
      // of BottomTrait, it will compile...
      class Demo implements BottomTrait<String> {}
      
       $ ./gradlew clean cG
      :clean
      :compileJava UP-TO-DATE
      :compileGroovy
      startup failed:
      /Users/jeff/t/generictraits/src/main/groovy/demo/Demo.groovy: -1: The return type of java.lang.Object getSomething() in demo.Demo is incompatible with java.lang.String in demo.TopTrait
      . At [-1:-1]  @ line -1, column -1.
      1 error
      
      :compileGroovy FAILED
      
      FAILURE: Build failed with an exception.
      
      * What went wrong:
      Execution failed for task ':compileGroovy'.
      > Compilation failed; see the compiler error output for details.
      
      * Try:
      Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
      
      BUILD FAILED
      
      Total time: 2.123 secs
      

      Attachments

        Activity

          People

            emilles Eric Milles
            jeffscottbrown Jeff Scott Brown
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 20m
                20m