Bug 122617 - [1.5][compiler] Compiler misses return type substitutability error with multiple inheritance and overriding method
Summary: [1.5][compiler] Compiler misses return type substitutability error with multi...
Status: RESOLVED DUPLICATE of bug 122881
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-04 07:05 EST by Markus Keller CLA
Modified: 2006-01-23 13:18 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2006-01-04 07:05:59 EST
I20051220-0800

From the news:
--------------------------------------------------
Subject: Multiple inheritance and covariance subtyping in Java 1.5 and jdt core

IC.java:

interface IA {
    IA op();
}

interface IB {
    IB op();
}

public interface IC extends IA, IB {
    IC op();
}


These classes compile with eclipse and compiler compliance level 5.0 but don't compile with my sun jdk 1.5.0:

> javac -version IC.java
javac 1.5.0
IC.java:9: types IB and IA are incompatible; both define op(), but with unrelated return types
public interface IC extends IA, IB {
       ^
1error 
-----------------------------------------------

The existence of IC#op() seems to suppress the return type substitutability check. As per JLS3 8.4.8.4, "A compile-time error occurs if, for any two such inherited methods, one of the methods is not return type substitutable for the other".
Comment 1 Markus Keller CLA 2006-01-23 13:18:32 EST
Actually, the reference to JLS3 8.4.8.4 does not apply here (it's for classes).

Rather, 9.4.1 should be consulted:
"An interface inherits from its direct superinterfaces all methods of the superinterfaces that are not overridden by a declaration in the interface.
It is possible for an interface to inherit several methods with override-equivalent signatures (ยง8.4.2). Such a situation does not in itself cause a compile-time error. The interface is considered to inherit all the methods. However, one of the inherited methods must must be return type substitutable for any other inherited method; otherwise, a compile-time error occurs"

In this example, "IC op()" in interface IC overrides both of the other methods, so IC does not inherit any op() method! Therefore, the Eclipse compiler is correct in allowing this (with the fix for 122881 comment 3), but jdk1.5.0_06 is wrong.

Marking as dup of bug 122881.

*** This bug has been marked as a duplicate of 122881 ***