You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniel Sun (JIRA)" <ji...@apache.org> on 2018/05/11 06:41:00 UTC
[jira] [Resolved] (GROOVY-7691) Type checking error on generic
property with covariant type in subclass
[ https://issues.apache.org/jira/browse/GROOVY-7691?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Daniel Sun resolved GROOVY-7691.
--------------------------------
Resolution: Fixed
Assignee: Daniel Sun
It is fixed by the proposed PR. Thanks!
https://github.com/apache/groovy/pull/198
> 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: Daniel Sun
> Priority: Major
> Labels: test
>
> 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 == 42L
> {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
(v7.6.3#76005)