Bug 536911 - [compiler] ECJ gives priority to same class overloads
Summary: [compiler] ECJ gives priority to same class overloads
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.9   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-11 07:33 EDT by Jens Lideström CLA
Modified: 2023-12-19 02:12 EST (History)
0 users

See Also:


Attachments
Code example that demonstrates the problem. (1.59 KB, text/x-java)
2018-07-11 07:33 EDT, Jens Lideström CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jens Lideström CLA 2018-07-11 07:33:19 EDT
Created attachment 274935 [details]
Code example that demonstrates the problem.

The ejc compiler seems to give priority to methods from class of the reference type when resolving method overloads. The result is that ejc accepts some method calls which should be considered to be ambiguous.

This is compared to javac, which rejects these calls.

### Software verions

ejc version: I20180710
javac version: 1.8.0_92

Also tested with the same result with JDT 3.13.4, Eclipse Oxygen.3a Release (4.7.3a) Build id: 20180405-1200

### Output from the compilers

Output from the compilers when compiling the example code:

$ java -jar ecj-I20180710-2000.jar -classpath rt.jar -source 1.9 OverloadExtensionGenericsBug.java 
$ 
$ javac OverloadExtensionGenericsBug.java 
OverloadExtensionGenericsBug.java:34: error: reference to m is ambiguous
        b.m(i); // Works in ejc, compile error in javac: Method is ambiguous
         ^
  both method m(T) in A and method m(Integer) in B match
  where T is a type-variable:
    T extends Object declared in class A
1 error

### Example code

class A<T> {
    void m(T a) {}
    void m(Integer a) {}
}

class B<T> extends A<T> {
    @Override
    void m(Integer a) {}
    
    // Adding this makes both calls to m result in compile errors
//    @Override
//    public void m(T a) {
//        System.out.println("B#m(T)");
//    }
}

public class OverloadExtensionGenericsBug {
    public static void main(String[] args) {
        Integer i = 0;
        
        B<Integer> b = new B<>();
        b.m(i); // Works in ejc, compile error in javac: Method is ambiguous

//        A<Integer> a = b;
//        a.m(i); // Compile error in  both ejc and javac: Method is ambiguous
    }
}
Comment 1 Eclipse Genie CLA 2020-08-14 08:47:38 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 2 Jens Lideström CLA 2021-12-28 13:50:48 EST
This problem still occurs in Eclipse 2022-03 (4.23) Build id: I20211223-1800.
Comment 3 Eclipse Genie CLA 2023-12-19 02:12:33 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.