| Summary: | [1.8][compile] Access to invisible members from within lambda expression produces misleading compilation error | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Lukas Eder <lukas.eder> |
| Component: | Core | Assignee: | Sasikanth Bharadwaj <sasikanth.bharadwaj> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | manoj.palat |
| Version: | 4.5 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows NT | ||
| Whiteboard: | stalebug | ||
I'm using Eclipse 4.5.0 M5, btw 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. |
The following program doesn't compile because Y.y is invisible to X ------------------------------------------------------------ package test; import static test.Y.y; import java.util.function.Function; import java.util.stream.Stream; public class X { void fail() { Stream<Y<Integer>> stream = Stream.of(new Y<>(1)); m(stream, (Y<Integer> y) -> y(y.y)); // ^ ^ ^ actual problem here (1) // | +--- misleading compilation error here (2) // +---- additional misleading compilation error here (3) } static <T, U> void m(Stream<Y<T>> stream, Function<Y<T>, Y<U>> unzipper) { } } class Y<T> { private final T y; Y(T y) { this.y = y; } static <T> Y<T> y(T y) { return new Y<>(y); } } ------------------------------------------------------------ The actual problem (1) is the fact that y.y cannot be accessed from within the lambda expression. A fix would be to make the Y.y attribute public, for instance. But Eclipse also reports an error on the lambda argument type of Y<Integer> (2). The error message is: > Lambda expression's parameter y is expected to be of type Y<T> That error is incorrect, of course, and it produces a third error message (3) on the method call itself: > The method m(Stream<Y<T>>, Function<Y<T>,Y<U>>) in the type X > is not applicable for the arguments > (Stream<Y<Integer>>, (Y<Integer> y) -> {})