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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.6-beta-1
    • 1.5.7, 1.6-beta-2
    • None
    • 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.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: