Frank Pavageau created GROOVY-7691:
--------------------------------------

             Summary: Type checking error on generic property with covariant 
type in subclass
                 Key: GROOVY-7691
                 URL: https://issues.apache.org/jira/browse/GROOVY-7691
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
    Affects Versions: 2.4.5
            Reporter: Frank Pavageau
            Assignee: Cédric Champeau


A property declared with a generic type in a superclass is not seen with the 
correct covariant type in a subclass narrowing the type:
{code}
abstract class AbstractNumberWrapper<S extends Number> {
    protected final S number;

    AbstractNumberWrapper(S number) {
        this.number = number
    }
}
class LongWrapper<S extends Long> extends AbstractNumberWrapper<S> {
    LongWrapper(S longNumber) {
        super(longNumber)
    }

    S getValue() {
        return number;
    }
}
assert new LongWrapper<Long>(42L).value == 42
{code}
raises the following error when type checked:
{noformat}
[Static type checking] - Cannot return value of type java.lang.Number on method 
returning type S
 @ line 15, column 28.
                       return number;
                              ^

1 error{noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to