groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-7495) Diamond inheritance of interfaces makes method return type incompatible
Date Fri, 10 Jul 2015 00:01:01 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-7495?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14621473#comment-14621473
] 

ASF GitHub Bot commented on GROOVY-7495:
----------------------------------------

Github user paulk-asert closed the pull request at:

    https://github.com/apache/incubator-groovy/pull/58


> 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
>            Assignee: Jochen Theodorou
>             Fix For: 2.4.4, 2.5.0-beta-1
>
>
> 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)

Mime
View raw message