Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 541532

Summary: [11] JEP 323: Local-Variable Syntax for Lambda parameters does not work for Function and Predicate
Product: [Eclipse Project] JDT Reporter: Alexander Rühl <alexander.ruehl>
Component: CoreAssignee: Manoj N Palat <manoj.palat>
Status: VERIFIED FIXED QA Contact: Stephan Herrmann <stephan.herrmann>
Severity: major    
Priority: P3 CC: jarthana, manoj.palat, ryan.ulch, serowski, sig-rnd-sat-ecj-bugs, stephan.herrmann, svorobyov
Version: 4.9   
Target Milestone: 4.11 M3   
Hardware: PC   
OS: Windows 10   
See Also: https://git.eclipse.org/r/135596
https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=4c49f905582020b5bbace350773b0eba3dc92fb8
https://bugs.eclipse.org/bugs/show_bug.cgi?id=543856
Whiteboard:
Attachments:
Description Flags
Demo maven project demonstrating error none

Description Alexander Rühl CLA 2018-11-24 17:46:28 EST
Eclipse compiler on JDK 11 project and compiler setting does work in a Prdicate, e.g. filter on list:

list.stream()
  .filter(s -> s.length() == 1)
  .forEach(System.out::println);

However, it does not work in a unary operator Function, e.g. map on list:

list.stream()
  .map((var s) -> s.toLowerCase())
  .forEach(System.out::println);

This results in 2 Java Problems:
- The method map(Function<? super String,? extends R>) in the type Stream<String> is not applicable for the arguments ((var s) -> {})
- The method toLowerCase() is undefined for the type ? super String

The same class compiled directly with javac works fine for both cases.
Comment 1 Alexander Rühl CLA 2018-11-24 17:54:47 EST
Sorry, forgot "var" in case 1 with filter if I add it like that

list.stream()
  .filter((var s) -> s.length() == 1)
  .forEach(System.out::println);

it does not work either and shows also 2 Problems: 
- The method filter(Predicate<? super String>) in the type Stream<String> is not applicable for the arguments ((var s) -> {})
- The method length() is undefined for the type ? super String

So error is not limited to unary operator Function, but also in Predicate.
Comment 2 Stephan Herrmann CLA 2018-11-25 10:10:33 EST
Eclipse 4.9 does not support Java 11 (incl. JEP 323).

Do you have Support for Java 11 installed? One of:
- https://marketplace.eclipse.org/content/java-11-support-eclipse-2018-09-49
- using a recent milestone or I-build of Eclipse

Otherwise this would be a duplicate of bug 531711.
Comment 3 Alexander Rühl CLA 2018-11-25 12:06:05 EST
Yes, I installed the current version of the Java 11 support from marketplace.

IDE is 20180917-1800 and I already did a check for updates and installed JDT update, but didn't change the error behaviour. 

Also, a fresh download, both EE and SE edition of IDE with current Java 11 support plugin does not solve it.

Then I downloaded the current OpenJDK 11 version - still no change.

So from what I can see, JEP 323 might work partly with your sample in help section of plugin, so it accepts the lambda usage syntax, but does not for this correct statement, which compiles fine with pure javac or Maven build:

list.stream()
  .map((var s) -> s.toLowerCase())
  .forEach(System.out::println);
Comment 4 Alexander Rühl CLA 2018-11-25 12:23:12 EST
Created attachment 276687 [details]
Demo maven project demonstrating error
Comment 5 Alexander Rühl CLA 2018-11-25 12:23:45 EST
I also tried the current IDE milestone M2 of 4.10 (Build 20181108-1653).
It is also not able to compile the mentioned command.

Find attached a simple demo maven project which builds fine with
mvn clean install
and a JAVA_HOME set to OpenJDK 11.

The same project imported in recent Eclipse IDE with Java 11 support does not.
Comment 6 Ryan Ulch CLA 2019-01-17 12:30:13 EST
I am also experiencing this issue. Any chance this is getting looked at soon? Still an issue with the R4_10_maintenance branch (built commit tagged with R4_10).
Comment 7 Stephan Herrmann CLA 2019-01-22 18:26:42 EST
I can reproduce the problem from comment 0 in today's HEAD.

Definitely there's no reason that a program should become invalid just by inserting 'var'.

@Manoj, via bug 534787 you introduced argumentsTypeVar() which in my understanding should produce mostly the same semantics as argumentsTypeElided(). However, the latter is called from 17 locations, whereas the former only from 1.

Couldn't we treat both cases the same way, by letting argumentsTypeElided() answer true also for 'var'? What difference does 'var' make for compilation?
Comment 8 Manoj N Palat CLA 2019-01-23 00:01:31 EST
(In reply to Stephan Herrmann from comment #7)
> I can reproduce the problem from comment 0 in today's HEAD.
> 
> Definitely there's no reason that a program should become invalid just by
> inserting 'var'.
> 
> @Manoj, via bug 534787 you introduced argumentsTypeVar() which in my
> understanding should produce mostly the same semantics as
> argumentsTypeElided(). However, the latter is called from 17 locations,
> whereas the former only from 1.
> 
> Couldn't we treat both cases the same way, by letting argumentsTypeElided()
> answer true also for 'var'? What difference does 'var' make for compilation?

@Stephan: Thanks for finding the root cause of the issue. Yes, I agree that var should be treated at par/identical with argumentsTypeElided - will submit a patch in that effect.
Comment 9 Eclipse Genie CLA 2019-01-23 00:03:03 EST
New Gerrit change created: https://git.eclipse.org/r/135596
Comment 11 Ryan Ulch CLA 2019-01-23 13:02:21 EST
(In reply to Eclipse Genie from comment #10)
> Gerrit change https://git.eclipse.org/r/135596 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=4c49f905582020b5bbace350773b0eba3dc92fb8

I have confirmed that this commit resolves my issues. Thanks!
Comment 12 Manoj N Palat CLA 2019-01-23 21:18:02 EST
(In reply to Ryan Ulch from comment #11)

> 
> I have confirmed that this commit resolves my issues. Thanks!

Thanks Ryan for the confirmation - I am moving this to resolved.
Comment 13 Stephan Herrmann CLA 2019-01-26 09:58:20 EST
The test introduced here triggered failure in RUN_JAVAC mode[1]. I'm fixing this via bug 543856.

[1] https://ci.eclipse.org/jdt/job/eclipse.jdt.core-run.javac-11/15/testReport/org.eclipse.jdt.core.tests.compiler.regression/JEP323VarLambdaParamsTest/testBug541532_01___11/
Comment 14 Stephan Herrmann CLA 2019-02-07 07:15:55 EST
*** Bug 544217 has been marked as a duplicate of this bug. ***
Comment 15 Jay Arthanareeswaran CLA 2019-02-20 00:19:56 EST
verified for 4.11 M3 using build I20190219-1800.
Comment 16 Stephan Herrmann CLA 2019-03-19 08:33:13 EDT
*** Bug 545542 has been marked as a duplicate of this bug. ***