Groovy
  1. Groovy
  2. GROOVY-2829

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

    Details

    • Type: Bug Bug
    • Status: 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

      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

        paulk@asert.com.au created issue -
        Jochen Theodorou made changes -
        Field Original Value New Value
        Fix Version/s 1.6-beta-2 [ 14261 ]
        Paul King made changes -
        Assignee Paul King [ paulk ] Jochen Theodorou [ blackdrag ]
        Jochen Theodorou made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Closed [ 6 ]
        Paul King made changes -
        Resolution Fixed [ 1 ]
        Status Closed [ 6 ] Reopened [ 4 ]
        Paul King made changes -
        Attachment groovy2829_additional.patch [ 34599 ]
        Paul King made changes -
        Resolution Fixed [ 1 ]
        Status Reopened [ 4 ] Resolved [ 5 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12731849 ] Default workflow, editable Closed status [ 12743749 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12973410 ] Default workflow, editable Closed status [ 12974558 ]
        Mark Thomas made changes -
        Reporter Paul King [ paulk@asert.com.au ] Paul King [ paulk ]

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development