Bug 80745 - [1.5][compiler] Two interfaces with methods with compatible return types are compatible
Summary: [1.5][compiler] Two interfaces with methods with compatible return types are ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-10 19:27 EST by Olivier Thomann CLA
Modified: 2005-02-16 08:58 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2004-12-10 19:27:50 EST
Using latest, these two interfaces are incompatible.

interface I {
	Number foo();
}
interface J {
	Integer foo();
}

This means that it is not possible to compare them using instanceof. Even if the
result of the instanceof call is false, at least it compiles.

interface I {
	Number foo();
}
interface J {
	Integer foo();
}

public class X implements I, J {
	public Integer foo() {return 1;}
	
	public static void main(String argv[]) {
		I c1 = null;
		System.out.print(c1 instanceof J);
	}
}

----------
1. ERROR in C:\tests_sources\X.java (at line 13)
	System.out.print(c1 instanceof J);
	                 ^^^^^^^^^^^^^^^
Incompatible conditional operand types I and J
----------
1 problem (1 error)
Comment 1 Philipe Mulet CLA 2004-12-15 08:12:44 EST
Expression#checkCastTypeCompatibility need to be tuned to support
covariance/substitution. Need some entry point in method verifier.
Comment 2 Kent Johnson CLA 2005-01-12 08:19:08 EST
Philippe: So what question do you need to ask?
Comment 3 Philipe Mulet CLA 2005-01-12 08:58:40 EST
In this block of code near the bottom of the cast compatibility rules, we are
checking whether the 2 interfaces are cast compatible:

...
for (int j = 0; j < exprMethodsLength; j++) {
  if ((castTypeMethods[i].returnType != expressionTypeMethods[j].returnType)
 && (CharOperation.equals(castTypeMethods[i].selector,
expressionTypeMethods[j].selector)) 
 && castTypeMethods[i].areParametersEqual(expressionTypeMethods[j])) {
							return false;
...

these rules obviously do not play the 1.5 semantics.
Please check how JLS3 have evolved on this very topic. I suspect you need to
compare methods in a similar way to what method verifier does when determining
if one overrides another one.
Comment 4 Kent Johnson CLA 2005-01-13 15:54:51 EST
Added MethodVerify test033
Comment 5 Philipe Mulet CLA 2005-02-10 07:49:07 EST
Actually, rules are even simpler. We always allow cast to interface from 1.5 on
(a subtype may implement it).
Comment 6 Philipe Mulet CLA 2005-02-10 07:49:36 EST
also see bug 84743
Comment 7 David Audel CLA 2005-02-16 08:58:53 EST
Verified in I20050215-2300