Bug 99106 - [1.5][compiler] Ambiguous method error because methods don't override in eclipse
Summary: [1.5][compiler] Ambiguous method error because methods don't override in eclipse
Status: CLOSED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.1 RC2   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-09 04:30 EDT by Markus Keller CLA
Modified: 2005-06-10 13:32 EDT (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 Markus Keller CLA 2005-06-09 04:30:21 EDT
N20050609-0010

Javac 1.5.0_03-b07 compiles this code and makes Ex#method(..) override Top#method().

Eclipse rejects the first call to ex.method(..) with this error:
"The method method(Object, Object) is ambiguous for the type Ex".
IMethodBinding#overrides(..) says that Ex#method(..) does not override Top#method().

public class Try {
    public static void main(String[] args) {
        Ex ex= new Ex();
        ex.method("Eclipse1", new Integer(1));
        Top top= ex;
        top.method("Eclipse2", new Integer(2));
    }
}

class Top<TC> {
    <TM> void method(TC cTop, TM mTop) { System.out.println("Top"); }
}

class Ex<C> extends Top<C> {
    <M> void method(C cEx, M mEx) { System.out.println("Ex"); }
}


When I change Ex to ...
class Ex<C extends String> extends Top<C> {
    <M extends Integer> void method(C cEx, M mEx) { System.out.println("Ex"); }
}
... then the two compilers agree that the methods don't override and accept the
program.
Comment 1 Kent Johnson CLA 2005-06-09 10:27:36 EDT
Changing Ex to be:

class Ex<C> extends Top<C> {
    @Override <M> void method(C cEx, M mEx) { System.out.println("Ex"); }
}

is accepted by both Eclipse & javac.

IMethodBinding#overrides() must have a bug if its not accepting this case.
Comment 2 Kent Johnson CLA 2005-06-09 10:35:18 EDT
This case works 'properly' as it reports the unchecked warning:

class Try {
    public static void main(String[] args) {
        new Ex().method2(new Integer(1));
    }
}

class Top<TC> {
    <TM> void method2(TM mTop) { System.out.println("Top"); }
}

class Ex<C> extends Top<C> {
    @Override <M> void method2(M mEx) { System.out.println("Ex"); }
}
Comment 3 Kent Johnson CLA 2005-06-09 10:52:46 EDT
Here is the full case, where we currently fail the 2 messages sends with type 
args (all 4 should be unchecked warnings):

class Try {
    public static void main(String[] args) {
        Ex ex= new Ex();
        ex.method("Eclipse1", new Integer(1));
        ex.method2(new Integer(1));
        ex.method3(new Integer(1));
        ex.method4(new Integer(1));
    }
}

class Top<TC> {
    <TM> void method(TC cTop, TM mTop) { System.out.println("Top"); }
    <TM> void method2(TM mTop) { System.out.println("Top"); }
    void method3(TC cTop) { System.out.println("Top"); }
    <TM> void method4(TC cTop) { System.out.println("Top"); }
}

class Ex<C> extends Top<C> {
    @Override <M> void method(C cEx, M mEx) { System.out.println("Ex"); }
    @Override <M> void method2(M mEx) { System.out.println("Ex"); }
    @Override void method3(C cEx) { System.out.println("Ex"); }
    @Override <M> void method4(C cEx) { System.out.println("Ex"); }
}
Comment 4 Kent Johnson CLA 2005-06-09 11:53:18 EDT
This is only a problem with Raw types, this case works fine:

class Try {
    public static void main(String[] args) {
        Ex<String> ex= new Ex<String>();
        ex.method("Eclipse1", new Integer(1));
        ex.method2(new Integer(1));
        ex.method3("Eclipse1");
        ex.method4("Eclipse1");
    }
}

class Top<TC> {
    <TM> void method(TC cTop, TM mTop) { System.out.println("Top"); }
    <TM> void method2(TM mTop) { System.out.println("Top"); }
    void method3(TC cTop) { System.out.println("Top"); }
    <TM> void method4(TC cTop) { System.out.println("Top"); }
}

class Ex<C> extends Top<C> {
    @Override <M> void method(C cEx, M mEx) { System.out.println("Ex"); }
    @Override <M> void method2(M mEx) { System.out.println("Ex"); }
    @Override void method3(C cEx) { System.out.println("Ex"); }
    @Override <M> void method4(C cEx) { System.out.println("Ex"); }
}
Comment 5 Kent Johnson CLA 2005-06-09 14:55:06 EDT
Added MethodVerify test061 & 62.

Needs to be uncommented when fix is released.

this.tiebreakMethod = this.isRaw ? this : new ParameterizedGenericMethodBinding
(this.originalMethod, (RawTypeBinding)null, this.environment);
Comment 6 Philipe Mulet CLA 2005-06-10 03:29:21 EDT
Tests enabled. Fix released for integration.
Comment 7 Frederic Fusier CLA 2005-06-10 12:29:00 EDT
Verified for 3.1 RC2 using build I20050610-0010
Comment 8 Olivier Thomann CLA 2005-06-10 13:32:57 EDT
Verified in I20050610-1200.