You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2015/07/09 09:43:05 UTC
[jira] [Commented] (GROOVY-7495) Diamond inheritance of interfaces
makes method return type incompatible
[ https://issues.apache.org/jira/browse/GROOVY-7495?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14620061#comment-14620061 ]
ASF GitHub Bot commented on GROOVY-7495:
----------------------------------------
GitHub user paulk-asert opened a pull request:
https://github.com/apache/incubator-groovy/pull/58
GROOVY-7495: Diamond inheritance of interfaces makes method return ty…
…pe incompatible
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/paulk-asert/incubator-groovy groovy7495
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-groovy/pull/58.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #58
----
commit bdec939be79c133dc4e26837ad9a6b2c7ecd5dda
Author: paulk <pa...@asert.com.au>
Date: 2015-07-09T07:41:18Z
GROOVY-7495: Diamond inheritance of interfaces makes method return type incompatible
----
> Diamond inheritance of interfaces makes method return type incompatible
> -----------------------------------------------------------------------
>
> Key: GROOVY-7495
> URL: https://issues.apache.org/jira/browse/GROOVY-7495
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 2.3.10, 2.4.3
> Reporter: Lóránt Pintér
>
> While working on Gradle, I bumped into a failure with the Groovy compiler that works fine in Java.
> Example code that fails with both Groovy compiler 2.3.10 and 2.4.3:
> {code:title=Groovy}
> interface Item {}
> interface DerivedItem extends Item {}
> interface Base {
> Item getItem()
> }
> class BaseImpl implements Base {
> Item getItem() { null }
> }
> interface First extends Base {
> DerivedItem getItem()
> }
> class FirstImpl extends BaseImpl implements First {
> DerivedItem getItem() { null }
> }
> interface Second extends First {}
> class SecondImpl extends FirstImpl implements Second {}
> {code}
> The error message is:
> {code}
> Script1.groovy: 8: The return type of Item getItem() in BaseImpl is incompatible with DerivedItem in First. At [8:3] @ line 8, column 3.
> Item getItem() { null }
> ^
> {code}
> However, changing the implementation of {{SecondImpl}} like this fixes the compile error:
> {code:title=Fixed Groovy}
> class SecondImpl extends FirstImpl implements Second {
> DerivedItem getItem() { super.item }
> }
> {code}
> The equivalent code compiles fine in Java:
> {code:title=Java}
> public class CompileJava {
> interface Item {}
> interface DerivedItem extends Item {}
>
> interface Base {
> Item getItem();
> }
> class BaseImpl implements Base {
> public Item getItem() { return null; }
> }
>
> interface First extends Base {
> DerivedItem getItem();
> }
>
> class FirstImpl extends BaseImpl implements First {
> public DerivedItem getItem() { return null; }
> }
>
> interface Second extends First {}
> class SecondImpl extends FirstImpl implements Second {}
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)