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

Compilation error with covariant return types (incompatible types)

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.6
    • Fix Version/s: 2.0.4, 1.8.9
    • Component/s: Compiler
    • Labels:
      None
    • Environment:
      Linux, jdk 1.6.0u31 (also reproducible with 1.7)

      Description

      Given the following files:

      pkg/Base.java
      package pkg;
      public interface Base {
          Base doSomething();
      }
      
      pkg/Child.java
      package pkg;
      public interface Child extends Base {
          Child doSomething();
      }
      
      pkg/GChild.groovy
      package pkg;
      class GChild implements Child {
          Child doSomething() {
              return this
          }
      }
      

      When I try to compile this, groovyc complains about incompatible return types:

      $ javac pkg/*.java
      $ groovyc pkg/*.groovy
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      pkg/GChild.groovy: 3: The return type of pkg.Child doSomething() in pkg.GChild is incompatible with pkg.Base doSomething() in pkg.Base
      . At [3:2]  @ line 3, column 2.
              Child doSomething() {
          ^
      
      1 error
      
      $ javac -version
      javac 1.6.0_31
      $ groovyc -version
      Groovy compiler version 1.8.6
      Copyright 2003-2011 The Codehaus. http://groovy.codehaus.org/
      
      $
      

      A very similar (almost identical) issue has already been reported here: https://jira.codehaus.org/browse/GROOVY-2829 (marked as fixed in 1.5.7 and 1.6-beta2)

        Attachments

          Activity

            People

            • Assignee:
              melix C├ędric Champeau
              Reporter:
              rherzog Raffael Herzog
            • Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: