Community
Participate
Working Groups
When i use a loop in a lambda that could be used as Consumer or Function it becomes ambiguous. This happens when the loop is the last statement. Everything works fine if compiled directly with javac. Here is a minimal example: public class Test { public static class A{ public void a(Consumer<Object> task){ } public <R> R a(Function<Object, R> task){ return null; } } public static void main(String[] args) { A a = new A(); //okay a.a(task -> { }); //not okay: //"The method a(Consumer<Object>) is ambiguous for the type Test.A" a.a(task -> { for (int i = 0; i < 1; i++) { } }); //okay a.a(task -> { for (int i = 0; i < 1; i++) { } ; }); } }
I can reproduce, also with other kinds of loops. Apparently we fail to see that the lambda is not value compatible.
SO discussion: http://stackoverflow.com/questions/38972060/for-loop-in-lambda-makes-it-ambiguous
LE.isPotentiallyCompatibleWith() does a rudimentary shape analysis on an as yet unresolved lambda causing all the loop statements to answer true in doesNotCompleteNormally() (because cst == null). While dealing with unresolved statements, we cannot accurately say whether the lambda is value compatible or not, so we should probably use cachedResolvedCopy() with anyTargetOk set to true to determine the shape of the lambda, and may be fall back on the simple minded analysis if this fails
bulk move out of 4.8
Bulk move out of 4.9
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.
I am pretty sure this is still relevant. The fact that some analysis has already been done with a possible direction for a fix means a possibility of a contributor coming up with a fix. Let's hope so.