groovy
  1. groovy
  2. GROOVY-2829

Groovy's class verification doesn't allow for covariant return types

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6-beta-1
    • Fix Version/s: 1.5.7, 1.6-beta-2
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      1

      Description

      Given these Java interfaces:

      import java.util.List;
      
      public interface Base {
          List foo();
      }
      
      import java.util.ArrayList;
      
      public interface Child extends Base {
          ArrayList foo();
      }
      

      Java allows the return type for methods to be the most specified or a derived type:

      import java.util.ArrayList;
      
      public class JavaChildImpl implements Child {
          public ArrayList foo() {
              return null;
          }
      }
      

      But compiling this Groovy script:

      class GroovyChildImpl implements Child {
          public ArrayList foo() {
              return null
          }
      }
      

      yields:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, GroovyChildImpl.groovy: 2: the return type is incompatible with java.util.List foo() in Base.
      Node: org.codehaus.groovy.ast.MethodNode. At [2:5]  @ line 2, column 5.
             public ArrayList foo() {
             ^
      
      1 error
      

      Attached patch fixes this problem.

        Activity

        Hide
        Paul King added a comment -

        I only reopened because I realised that my original testcase wasn't complete enough. I will add in my patch as it covers the case you mention above.

        Show
        Paul King added a comment - I only reopened because I realised that my original testcase wasn't complete enough. I will add in my patch as it covers the case you mention above.
        Hide
        Paul King added a comment -

        was fixed about a week ago I believe

        Show
        Paul King added a comment - was fixed about a week ago I believe
        Hide
        Raffael Herzog added a comment -

        Looks like the problem has returned in 1.8.6. I'm running into this, exactly as described in the original posting.

        Show
        Raffael Herzog added a comment - Looks like the problem has returned in 1.8.6. I'm running into this, exactly as described in the original posting.
        Hide
        blackdrag blackdrag added a comment -

        Raffael, can you please fill a new issue and explain there what exactly your issue is? Do you mean the example in this issue no longer works?

        Show
        blackdrag blackdrag added a comment - Raffael, can you please fill a new issue and explain there what exactly your issue is? Do you mean the example in this issue no longer works?
        Hide
        Raffael Herzog added a comment -

        Done: https://jira.codehaus.org/browse/GROOVY-5418

        And no, the issue is very similar, but the example in this issue should still work, AFAICS.

        Show
        Raffael Herzog added a comment - Done: https://jira.codehaus.org/browse/GROOVY-5418 And no, the issue is very similar, but the example in this issue should still work, AFAICS.

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            Paul King
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: