| Summary: | [1.8][inference] Failure to type inference in an "if" statement context | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Nathaniel Mishkin <mishkin> |
| Component: | Core | Assignee: | Stephan Herrmann <stephan.herrmann> |
| Status: | CLOSED NOT_ECLIPSE | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | baier, stephan.herrmann |
| Version: | 4.7 | ||
| Target Milestone: | 4.15 M3 | ||
| Hardware: | PC | ||
| OS: | Mac OS X | ||
| Whiteboard: | |||
We probably have a duplicate of this, but I don't have the time right now to search. The issue here is that JLS does not list this location (condition of an if) among the contexts that allow target typing to influence type inference. IIRC, javac invents a target type boolean (or Boolean) and illegally uses that during type inference. Will have another look after Java 9 has sailed. Maybe, we can push the spec authors to either update JLS or push the javac team to fix their implementation. IIRC, people were still undecided which direction it should go. bulk move out of 4.8 Bulk move out of 4.9 Regarding the "helpwanted" keyword: s.o. would have to ask Oracle (spec author and javac developer) to coordinate which behavior should be right / wrong - see comment 1. *** Bug 560024 has been marked as a duplicate of this bug. *** Here's the JDK bug: https://bugs.openjdk.java.net/browse/JDK-8179483 This has been idle for 3 years, I even pinged them March 2019, to no effect. Hence I won't hold my breath until it is fixed in JLS. Until they change the spec, ecj is right and javac is wrong in this regard. |
This code: public class Dummy { interface I { <T> T m(); } void foo() { I i = null; boolean x = i.m(); if (i.m()) { } } } compiles with javac. But on the "if" statement Eclipse reports the error: Type mismatch: cannot convert from Object to boolean