Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 427322 - [1.8][code assist] Eclipse hangs upon completion just past lambda
Summary: [1.8][code assist] Eclipse hangs upon completion just past lambda
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.3.1   Edit
Hardware: All All
: P3 critical (vote)
Target Milestone: BETA J8   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-03 14:54 EST by Cornel Izbasa CLA
Modified: 2021-04-27 16:10 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cornel Izbasa CLA 2014-02-03 14:54:11 EST
Start with the valid and working program below, computing a factorial:
------------------------------------------------
package java8.test;

public class Main {
	
	interface Duo {
		int apply(int n, Duo g);
	}
	
 	public static void main(String[] args) {
		Duo f = (n, g) -> n > 0 ? n * g.apply(n - 1, g) : 1;  
		System.out.println(f.apply(5, f));
	}
}
------------------------------------------------

then change the line declaring the "Duo f" variable as such:
------------------------------------------------
		Duo f = (n, g) -> n > 0 ? n * g.apply(n - 1, g) : 1, f.
------------------------------------------------

After the "." is entered after "f", Eclipse hangs and must be killed.
Comment 1 Srikanth Sankaran CLA 2014-02-04 05:35:42 EST
Fix and tests here: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=696ed15a1e8614ddbc6d608510de2603ca6573e4.

We were missing a call to the routine that handles lambda closure, instead 
waiting for the entire LocalVariableDeclaration to be reduced. However the
fact that we think we are inside the lambda expression even past its closure
interferes with subsequent parsing.

As a follow up, I'll shortly also hook up the new infrastructure for completion
support in lambda expressions into IProgressMonitor so timeouts would
automatically trigger and preclude such freezes.
Comment 2 Srikanth Sankaran CLA 2014-02-04 07:36:47 EST
(In reply to Srikanth Sankaran from comment #1)

> As a follow up, I'll shortly also hook up the new infrastructure for
> completion
> support in lambda expressions into IProgressMonitor so timeouts would
> automatically trigger and preclude such freezes.

I hooked up the CompletionParser infrastructure into the canonical of scheme
of things i.e IProgressMonitor that the CompletionEngine already tracks:

http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=7dbc472feab6f8985cd72052d6eaace52c7ea562
Comment 3 ANIRBAN CHAKRABORTY CLA 2014-02-24 15:02:59 EST
Verified as working for Eclipse + Java 8 RC1 using Kepler SR1 + Eclipse Java Development Tools Patch for Java 8 Support (BETA) 1.0.0.v20140220-2054
Comment 4 Cornel Izbasa CLA 2014-02-25 01:55:22 EST
Great, thanks for the fix!
Comment 5 Stephan Herrmann CLA 2021-04-27 16:10:37 EDT
On further look after bug 539685 I noticed that meanwhile we are giving real completion proposals, but those didn't look great. I was about to file a new bug to ensure that good proposals are made, but only then I noticed the syntax error at "1, f." - either the ',' or the '.' is wrong. 
When removing "1, ", the completion AST looks nice as of now.