Bug 529336 - ecj reports a compilation error while javac does not (The method X is ambiguous for the type Y)
Summary: ecj reports a compilation error while javac does not (The method X is ambiguo...
Status: REOPENED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.7.2   Edit
Hardware: PC Linux
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2018-01-01 18:31 EST by Jean-Noel Rouvignac CLA
Modified: 2022-06-27 06:51 EDT (History)
3 users (show)

See Also:


Attachments
Maven project showing the problem (1.67 KB, application/octet-stream)
2018-01-01 18:41 EST, Jean-Noel Rouvignac CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jean-Noel Rouvignac CLA 2018-01-01 18:31:30 EST
The following code shows up with a compilation error in Eclipse, while javac compiles it fine:


package com.bug;

public class CompilationBug {

    public static final class Menu<T> {
        public Menu<T> addOption(final String label, final T value) {
            return this;
        }

        public Menu<T> addOption(final String label, final MenuCallback callback) {
            return this;
        }
    }

    public interface MenuCallback {
        Object invoke(Object obj);
    }


    public static <T> void main() {
        final Menu<T> menu = new Menu<T>()
                .addOption("option1", console -> readValues(console));
    }

    private static Object readValues(Object obj) {
        return null;
    }
}



Eclipse shows the following 3 errors:

    Multiple markers at this line
	- The method addOption(String, T) is ambiguous for the type 
	 CompilationBug.Menu<T>
	- The target type of this expression must be a functional interface
	- console cannot be resolved to a variable


While running "mvn clean package" results in a successful build with javac version 1.8.0_151 .
Comment 1 Jean-Noel Rouvignac CLA 2018-01-01 18:41:54 EST
Created attachment 272090 [details]
Maven project showing the problem
Comment 2 Stephan Herrmann CLA 2018-01-12 17:41:05 EST
Ecj < 4.5M4 accepted this, so this relates to one of https://bugs.eclipse.org/bugs/buglist.cgi?classification=Eclipse&component=Core&list_id=17134836&order=bug_id%20DESC&product=JDT&query_format=advanced&resolution=FIXED&target_milestone=4.5%20M4

(no, I have no idea which of those caused it ...)
Comment 3 Andrey Loskutov CLA 2018-01-15 09:57:59 EST
(In reply to Stephan Herrmann from comment #2)
> Ecj < 4.5M4 accepted this, so this relates to one of

Sure?

I've tried 4.6.3, 4.7.1a, 4.7.2 - none of them compile this code, showing same errors as 4.8 head.
Comment 4 Stephan Herrmann CLA 2018-01-15 18:02:31 EST
(In reply to Andrey Loskutov from comment #3)
> (In reply to Stephan Herrmann from comment #2)
> > Ecj < 4.5M4 accepted this, so this relates to one of
> 
> Sure?
> 
> I've tried 4.6.3, 4.7.1a, 4.7.2 - none of them compile this code, showing
> same errors as 4.8 head.

Which of these versions are < 4.5M4 ? ;p

Yes, I have a pretty complete set of versions of ecj.jar and determined 4.5M4 as the first version rejecting the sample.
Comment 5 Andrey Loskutov CLA 2018-01-16 04:36:57 EST
(In reply to Stephan Herrmann from comment #4)
> Which of these versions are < 4.5M4 ? ;p

Sorry, I misread it with my old yes - I read 4.8M4.
Comment 6 Eclipse Genie CLA 2020-03-24 09:36:48 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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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 7 Stephan Herrmann CLA 2020-03-24 10:12:17 EDT
ecj already recognizes that the first overload (with T) is not applicable. This indicates that reporting ambiguity is probably not a good idea (even though JLS could theoretically require this, due to the strictly sequential process of analysis).

While analysis of overloading is not my top priority let's rather keep this one open.
Comment 8 Eclipse Genie CLA 2022-06-27 06:06:51 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 9 Tobias Gierke CLA 2022-06-27 06:51:34 EDT
Error still exists today the latest Java IDE version.

Version: 2022-06 (4.24.0)
Build id: 20220609-1112