Issue Details (XML | Word | Printable)

Key: GROOVY-2482
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Jochen Theodorou
Reporter: Mike Dillon
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
groovy

More problems with covariant return types

Created: 09/Jan/08 01:16 AM   Updated: 17/Jan/08 01:32 PM
Component/s: class generator
Affects Version/s: 1.5.2, 1.6-rc-2
Fix Version/s: 1.5.2, 1.6-rc-2

Time Tracking:
Not Specified

File Attachments: 1. File covariant-subclass.diff (2 kB)


Testcase included: yes


 Description  « Hide
This is related to the issue that was fixed in GROOVY-2320. Consider the following Java code:
import java.util.concurrent.*;

public class Test {
    public static void main(String[] args) {
        assert "x" == new CallableTask().call();
    }

    abstract static class AbstractCallableTask<T> implements Callable<T> { }

    abstract static class SubclassCallableTask<T> extends AbstractCallableTask<T> { }

    static class CallableTask extends SubclassCallableTask<String> {
        public String call() { return "x"; }
    }
}

This code compiles and works as expected, but I can't get the Groovy version to work:

import java.util.concurrent.*;

assert "x" == new CallableTask().call();

abstract class AbstractCallableTask<T> implements Callable<T> { }

abstract class SubclassCallableTask<T> extends AbstractCallableTask<T> { }

class CallableTask extends SubclassCallableTask<String> {
    public String call() { return "x"; }
}

I get the following exception:

$ groovy Test.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Test.groovy:
9: Can't have an abstract method in a non-abstract class. The class 'CallableTask' must be
declared abstract or the method 'java.lang.Object call()' must be implemented.
 @ line 9, column 1.
   class CallableTask extends SubclassCallableTask<String> {
   ^

1 error

I've tested with 1.5.0 and trunk. I have a patch to GenericsTest.groovy attached. I ran into this problem in the course of working with a Groovy subclass of this class: https://svn.mpl.ird.fr/ichthyop/trunk/ichthyop/util/SafeSwingWorker.java



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Jochen Theodorou added a comment - 17/Jan/08 01:32 PM
fixed