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

Bug 543842

Summary: [1.8][inference] passing conditionally selected method to map
Product: [Eclipse Project] JDT Reporter: Włodzimierz Rękawek <wrekawek>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: CLOSED MOVED QA Contact:
Severity: normal    
Priority: P3 CC: manoj.palat, stephan.herrmann
Version: 4.10   
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
URL: https://github.com/eclipse-jdt/eclipse.jdt.core/pull/296
Whiteboard:

Description Włodzimierz Rękawek CLA 2019-01-25 11:17:12 EST
Code like this 
Optional.ofNullable(BigDecimal.ZERO)
				.map((1 == 2) ? BigDecimal::negate : java.util.function.Function.identity())
				.orElse(BigDecimal.ZERO);
compiles with javac, but eclipse says its wrong :


The type of negate() from the type BigDecimal is BigDecimal, this is incompatible with the descriptor's return type: U

Compiler is set to 1.8 and default settings.
Comment 1 Stephan Herrmann CLA 2019-01-31 18:28:39 EST
This is accepted by ecj:

    Optional.ofNullable(BigDecimal.ZERO)
				.<BigDecimal>map((1 == 2) ? BigDecimal::negate : java.util.function.Function.identity())
				.orElse(BigDecimal.ZERO);


Ergo: a valid inference solution exists, which is accepted when explicitly specified.

But ecj rejects even this despite the target type:

    Optional<BigDecimal> r = Optional.ofNullable(BigDecimal.ZERO)
				.map((1 == 2) ? BigDecimal::negate : java.util.function.Function.identity());

At least this can be inferred:

    Function<? super BigDecimal,? extends BigDecimal> f = b ? BigDecimal::negate : java.util.function.Function.<BigDecimal>identity();

ecj versions prior to 4.5M4 actually accepted all this.

Will need to observe inference in the debugger to see where it fails.

Will try to look into this in the 4.11 time frame, time permitting.
Comment 2 Manoj N Palat CLA 2019-02-11 04:16:06 EST
Bulk move out of 4.11
Comment 3 Manoj N Palat CLA 2019-08-27 02:06:21 EDT
Bulk move out of 4.13
Comment 4 Eclipse Genie CLA 2022-08-01 05:13:53 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 5 Stephan Herrmann CLA 2022-08-05 12:24:50 EDT
I was lucky to identify what looks like the root cause here: we did not correctly implement the last bullet from JLS 15.12.2.1:

* A class instance creation expression, a method invocation expression, or an
expression of a standalone form (§15.2) is potentially compatible with any type.

Over to https://github.com/eclipse-jdt/eclipse.jdt.core/pull/296