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

Problem With Trait Generics

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.7
    • Fix Version/s: 4.0.0-alpha-1, 3.0.6
    • Component/s: None
    • Labels:
      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

            • Assignee:
              emilles Eric Milles
              Reporter:
              jeffscottbrown Jeff Scott Brown
            • Votes:
              1 Vote for this issue
              Watchers:
              4 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