Community
Participate
Working Groups
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 .
Created attachment 272090 [details] Maven project showing the problem
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 ...)
(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.
(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.
(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.
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.
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.
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.
Error still exists today the latest Java IDE version. Version: 2022-06 (4.24.0) Build id: 20220609-1112