Lóránt Pintér created GROOVY-7495: -------------------------------------
Summary: 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.4.3, 2.3.10 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)