Bug 499789 - loop in lambda makes it ambiguous
Summary: loop in lambda makes it ambiguous
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.6   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2016-08-16 17:08 EDT by Marcel Konopka CLA
Modified: 2022-08-12 05:25 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcel Konopka CLA 2016-08-16 17:08:01 EDT
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++) {
            }
            ;
        });
    }
}
Comment 1 Stephan Herrmann CLA 2016-08-16 17:20:19 EDT
I can reproduce, also with other kinds of loops.

Apparently we fail to see that the lambda is not value compatible.
Comment 3 Sasikanth Bharadwaj CLA 2016-08-30 01:09:40 EDT
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
Comment 4 Manoj N Palat CLA 2018-05-17 03:23:30 EDT
bulk move out of 4.8
Comment 5 Manoj N Palat CLA 2018-08-16 00:06:28 EDT
Bulk move out of 4.9
Comment 6 Eclipse Genie CLA 2022-08-11 16:07:14 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 7 Jay Arthanareeswaran CLA 2022-08-12 05:25:41 EDT
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.