Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 405139 - [1.8][code assist] Error in code assist suggestions in curly bracketed lambda body
Summary: [1.8][code assist] Error in code assist suggestions in curly bracketed lambda...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.3   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: BETA J8   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 402079
  Show dependency tree
 
Reported: 2013-04-08 06:06 EDT by ANIRBAN CHAKRABORTY CLA
Modified: 2013-11-30 19:57 EST (History)
3 users (show)

See Also:


Attachments
Applicable regression clean patch (43.15 KB, patch)
2013-05-03 05:52 EDT, ANIRBAN CHAKRABORTY CLA
no flags Details | Diff
Patch accommodating review comments. (47.36 KB, patch)
2013-06-07 03:39 EDT, ANIRBAN CHAKRABORTY CLA
no flags Details | Diff
Submitting refreshed patch (50.87 KB, patch)
2013-07-02 05:03 EDT, ANIRBAN CHAKRABORTY CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description ANIRBAN CHAKRABORTY CLA 2013-04-08 06:06:25 EDT
public interface Foo { 
	int run1(int s1, int s2);
}

interface X extends Foo{
	
    static Foo f = (x5, x6) -> {x<ctrl-space>
    		
}

x5, x6 are not suggested.
Comment 1 Srikanth Sankaran CLA 2013-04-08 06:14:44 EDT
(In reply to comment #0)

> x5, x6 are not suggested.

Just curious. What would a completed program look like ?
Comment 2 Srikanth Sankaran CLA 2013-04-08 06:28:45 EDT
This may be a more relevant example:

interface Foo { 
	int run1(int s1, int s2);
}

interface X extends Foo{
	
  static Foo f = (x512, x6) -> { System.out.println(x51|)
    		
}

No completion proposals at |
Comment 3 ANIRBAN CHAKRABORTY CLA 2013-04-08 06:31:46 EDT
(In reply to comment #1)
> (In reply to comment #0)
> 
> > x5, x6 are not suggested.
> 
> Just curious. What would a completed program look like ?

e.g

interface X extends Foo {
	
    static Foo f = (x5, x6) -> {return x5;};
    		
}
Comment 4 Srikanth Sankaran CLA 2013-04-08 06:35:08 EDT
(In reply to comment #3)
> (In reply to comment #1)
> > (In reply to comment #0)
> > 
> > > x5, x6 are not suggested.
> > 
> > Just curious. What would a completed program look like ?
> 
> e.g
> 
> interface X extends Foo {
> 	
>     static Foo f = (x5, x6) -> {return x5;};
>     		
> }

Right, this is not the same case as comment#0 and is similar to comment#2
case.
Comment 5 ANIRBAN CHAKRABORTY CLA 2013-04-19 02:48:14 EDT
Hello,
I'll be working on this.
Thanks
Anirban
Comment 6 ANIRBAN CHAKRABORTY CLA 2013-05-03 05:52:17 EDT
Created attachment 230450 [details]
Applicable regression clean patch

Applicable regression clean patch.
Comment 7 Srikanth Sankaran CLA 2013-05-08 07:35:06 EDT
The following completion attempt triggers an NPE:

// ---
interface I {
	int foo(int x);
}

public class X {
	void go() {
		I i = (argument) -> {
			if (true) {
				return arg|
			}
		}
	}
}
Comment 8 Srikanth Sankaran CLA 2013-05-08 08:01:36 EDT
(1) The following completion attempt triggers an NPE:

// ---
interface I {
	int foo(int x);
}

public class X {
	void go() {
		I i = (argument) -> {
			if (true) {
				return arg|
			}
		}
	}
}

(2) I am not sure the approach embodied in recoverFromStatementInBracedLambdaBody
is the right approach. Looks like it will work only in very specific scenarios.
There are a number of scenarios, where ungetting the current token and inserting
a TokenNameRBRACE is the WRONG thing to do - i.e it will not trigger the sequence
of rule reductions you are hoping for.

I am not sure if such attempts to force rule reductions can be successful
given how complex the grammar is.

(3) I get NPE at completion attempt in this snippet also:

interface I {
	int foo(int x);
}

public class X {
	void go() {
		I i = (argument) -> {
			argument == 0 ? argu|
		}
	}
}
Comment 9 ANIRBAN CHAKRABORTY CLA 2013-05-08 10:01:02 EDT
Hello Srikanth,
Thanks for the comments.
I'll take a re-look at the solution, keeping myself open to suggestions.
I'll come up with a solution soon.
Thanks
Anirban
Comment 10 ANIRBAN CHAKRABORTY CLA 2013-06-07 03:39:45 EDT
Created attachment 232071 [details]
Patch accommodating review comments.

Patch accommodating review comments.
Comment 11 ANIRBAN CHAKRABORTY CLA 2013-07-02 05:03:12 EDT
Created attachment 232973 [details]
Submitting refreshed patch

Submitting refreshed patch  (did not run regression on this one, ran on the original though).
Comment 12 Srikanth Sankaran CLA 2013-07-22 05:29:26 EDT
This patch looks much more complicated than needed. Please get rid of all
grammar + parser changes and submit a simpler patch and we will study it
in detail, thanks.
Comment 13 Martin Mathew CLA 2013-09-11 05:47:25 EDT
Consider the below snippet:
public class C1 {			
	I2 i2= () -> {
			syso| //invoke <Ctrl+Space> here
	};
}

@FunctionalInterface
interface I2{
	public void foo();
}

In the above example if we invoke content assist after 'syso' ideally it should be completed as 'System.out.println();', this is not happening inside a lambda expression.
Kindly take care of this scenario while fixing this bug.
Comment 14 Martin Mathew CLA 2013-11-19 09:03:57 EST
Consider the below code snippet:

import java.io.Serializable;

interface I {
    void doit();
}

public class X { 

// Invoke code assist<Ctrl+space> in this location gives 20+ suggestions
    Object o = (I & Serializable) () -> {};
// Invoke code assist<Ctrl+space> in this location gives just 4 template proposals
   
}

Invoking code assist just before and after a variable initialized using lambda gives different result. Will this be handled by this bug or should a new bug be created for the same?
Comment 15 Srikanth Sankaran CLA 2013-11-19 09:46:52 EST
(In reply to Manju Mathew from comment #14)

> Invoking code assist just before and after a variable initialized using
> lambda gives different result. Will this be handled by this bug or should a
> new bug be created for the same?

Please raise a separate bug - tagging it as BETA_JAVA8, thanks.
Comment 16 Srikanth Sankaran CLA 2013-11-29 15:27:50 EST
This got subsumed by the fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=407106. Tests have been added from here.