| Summary: | [1.8][compiler] Incorrect error: No enclosing instance of the type X is accessible in scope | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Srikanth Sankaran <srikanth_sankaran> |
| Component: | Core | Assignee: | Srikanth Sankaran <srikanth_sankaran> |
| Status: | VERIFIED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | noopur_gupta, stephan.herrmann |
| Version: | 4.4 | ||
| Target Milestone: | BETA J8 | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | |||
| Bug Depends on: | |||
| Bug Blocks: | 427787 | ||
See that javac 8b129 rejects this program incorrectly:
interface I {
X foo(int a);
}
public class X {
public void main(String[] args) {
class Local extends X {
Local(int a) {
System.out.println(a);
}
}
I i = Local::new;
i.foo(10);
}
}
as there being no suitable enclosing instance.
This required special treatment - when the local type captures outer locals, the situation gets tricky: the captured outer locals come *after* the functional interface parameters and there is no way the meta factory can handle that case. So I arranged to generate code for the method reference by treating it as an implicit lambda expression. Fix and tests here: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=d7bf97b0906e6821b36f900e536d18f1ccdddff2 Verified as working for Eclipse + Java 8 RC1 using Kepler SR2(RC4) + Eclipse Java Development Tools Patch for Java 8 Support (BETA) 1.0.0.v20140220-2054 |
The following program should compile, but is presently rejected: // -- interface I { X foo(int a); } public class X { public static void main(String[] args) { String s = "Blah"; class Local extends X { Local(int a) { System.out.println(a); System.out.println(s); } } I i = Local::new; // Incorrect error here. i.foo(10); } } Point is Local being in static context, does not have an enclosing instance.