Bug 162073 - [compiler] extraneous interface compatibility error
Summary: [compiler] extraneous interface compatibility error
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.3 M5   Edit
Assignee: Maxime Daniel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-24 09:20 EDT by Maxime Daniel CLA
Modified: 2007-02-06 06:47 EST (History)
0 users

See Also:


Attachments
Suggested fix + test cases modifications (8.51 KB, patch)
2006-10-26 07:43 EDT, Maxime Daniel CLA
no flags Details | Diff
Fix + (some more) test cases modifications (5.96 KB, patch)
2006-11-07 07:52 EST, Maxime Daniel CLA
no flags Details | Diff
Fix + test cases (10.08 KB, patch)
2007-01-24 03:10 EST, Maxime Daniel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Maxime Daniel CLA 2006-10-24 09:20:28 EDT
I20061003-0800
On the following test case, the compiler complains on X, contending that foo's return type is incompatible with I#foo, J#foo. This is wrong because X#foo has no parameter at all and cannot override J#foo.
interface I {
  <T extends Exception & Cloneable> T foo(Number n);
}
interface J extends I {
  XX foo(Number n);
}
public abstract class X implements J {
  void foo() {
  }
}
abstract class XX extends Exception implements Cloneable {}

Added AmbiguousMethodTest#32 (inactive) and 33.
Comment 1 Maxime Daniel CLA 2006-10-24 09:32:07 EDT
The error is not about X#foo at all (even if its presence conditions the behavior). It is kicked by the compatibility check on methods inherited from different paths. On the following variant, adding a complete foo implementation on X solves the issue - which should not be needed:
interface I {
  <T extends Exception & Cloneable> T foo(Number n);
}
interface J extends I {
  XX foo(Number n);
}
public abstract class X implements J {
  void foo() {
  }
  XX foo (Number n) {
    return null;
  }
}
abstract class XX extends Exception implements Cloneable {}

On yet another source, javac and Eclipse agree that J and K are incompatible because their foo(Number) methods have incompatible types:
interface I {
  <T extends Exception & Cloneable> T foo(Number n);
}
interface J extends I {
  XX foo(Number n);
}
interface K {
  NullPointerException foo(Number n);
}
public abstract class X implements J, K {
}
abstract class XX extends Exception implements Cloneable {} 

Changing the title accordingly and adding AmbiguousMethodTest#34.
Comment 2 Maxime Daniel CLA 2006-10-24 09:45:28 EDT
The declaration of X#foo() is not needed to show the bug. Modified test32 accordingly.
Comment 3 Maxime Daniel CLA 2006-10-26 07:43:43 EDT
Created attachment 52740 [details]
Suggested fix + test cases modifications

This patch essentially modifies MethodVerifier15#isInterfaceMethodImplemented by saying that a method which return type is merely compatible with the one of another method declared in a superinterface of its own declaring type can be considered as implementing the said method.
All JDT Core tests pass, with a few differences in error messages though (which are also taken into account in the patch).
Comment 4 Maxime Daniel CLA 2006-11-07 07:52:58 EST
Created attachment 53361 [details]
Fix + (some more) test cases modifications

A few test cases changed in HEAD, catching up.
Comment 5 Maxime Daniel CLA 2006-11-07 07:53:35 EST
Released for 3.3 M4.
Comment 6 Olivier Thomann CLA 2006-12-11 15:04:27 EST
Verified for 3.3M4 with I20061211-1119
Comment 7 Maxime Daniel CLA 2007-01-15 07:12:09 EST
This fix appeared to break other cases (see bug 168331). The correction for this is quite more involving than I thought initially, and touches other areas as well (especially upper bounds), hence I reopen the bug for now.
Comment 8 Philipe Mulet CLA 2007-01-17 06:34:15 EST
Removed 3.3M4 target milestone.
Comment 9 Maxime Daniel CLA 2007-01-24 03:10:25 EST
Created attachment 57406 [details]
Fix + test cases

Incorporated Kent's advice + improved coverage. We do not cover the most general cases yet, but I would contend that we should reconsider the handling of existential types on a more general basis first. The current patch covers the original test case and a series of incremental variants around it. If more complex cases arise in real settings, we should be able to handle them on an on demand basis.
Comment 10 Maxime Daniel CLA 2007-01-24 03:11:00 EST
Released for 3.3 M5.
Comment 11 David Audel CLA 2007-02-06 06:47:14 EST
Verified for 3.3 M5 using build I20070206-0010