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

Compilation error with covariant return types (incompatible types)

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.6
    • 2.0.4, 1.8.9
    • Compiler
    • None
    • 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

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            melix Cédric Champeau
            rherzog Raffael Herzog
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment