Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorssankaran2014-02-17 21:16:29 +0000
committerssankaran2014-02-17 21:16:29 +0000
commitd7bf97b0906e6821b36f900e536d18f1ccdddff2 (patch)
tree84e9fd62d14242a97e8150dbdc1f76ec25b3d5b9
parent78bbbeed8347e023a39893a354552d3196a82094 (diff)
downloadeclipse.jdt.core-d7bf97b0906e6821b36f900e536d18f1ccdddff2.tar.gz
eclipse.jdt.core-d7bf97b0906e6821b36f900e536d18f1ccdddff2.tar.xz
eclipse.jdt.core-d7bf97b0906e6821b36f900e536d18f1ccdddff2.zip
Fixed Bug 428261 - [1.8][compiler] Incorrect error: No enclosing
instance of the type X is accessible in scope
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java51
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java8
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java3
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java4
4 files changed, 62 insertions, 4 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java
index 73c3494859..2911feee15 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java
@@ -3319,6 +3319,57 @@ public void test428003a() { // full test case
"expression"
);
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428261, [1.8][compiler] Incorrect error: No enclosing instance of the type X is accessible in scope
+public void test428261() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X foo(int a);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " String s = \"Blah\";\n" +
+ " class Local extends X {\n" +
+ " Local(int a) {\n" +
+ " System.out.println(a);\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ " }\n" +
+ " I i = Local::new; // Incorrect error here.\n" +
+ " i.foo(10);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "10\n" +
+ "Blah"
+ );
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428261, [1.8][compiler] Incorrect error: No enclosing instance of the type X is accessible in scope
+public void test428261a() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X foo(int a);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " void goo() {\n" +
+ " class Local extends X {\n" +
+ " Local(int a) {\n" +
+ " System.out.println(a);\n" +
+ " }\n" +
+ " }\n" +
+ " I i = Local::new;\n" +
+ " i.foo(10);\n" +
+ " }\n" +
+ " public static void main(String [] args) {\n" +
+ " new X().goo();\n" +
+ " }\n" +
+ "}\n"
+ },
+ "10");
+}
public static Class testClass() {
return LambdaExpressionsTest.class;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java
index cfd6148276..b049245b39 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java
@@ -60,6 +60,7 @@ import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
import org.eclipse.jdt.internal.compiler.lookup.Scope;
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
+import org.eclipse.jdt.internal.compiler.lookup.SyntheticArgumentBinding;
import org.eclipse.jdt.internal.compiler.lookup.SyntheticMethodBinding;
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
@@ -153,12 +154,17 @@ public class ReferenceExpression extends FunctionalExpression implements Invocat
} finally {
currentScope.problemReporter().switchErrorHandlingPolicy(oldPolicy);
}
+ SyntheticArgumentBinding[] outerLocals = this.receiverType.syntheticOuterLocalVariables();
+ for (int i = 0, length = outerLocals == null ? 0 : outerLocals.length; i < length; i++)
+ implicitLambda.addSyntheticArgument(outerLocals[i].actualOuterLocalVariable);
+
implicitLambda.generateCode(currentScope, codeStream, valueRequired);
}
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
this.actualMethodBinding = this.binding; // grab before synthetics come into play.
- if (this.binding.isVarargs()) {
+ // Handle some special cases up front and transform them into implicit lambdas.
+ if (this.binding.isVarargs() || (isConstructorReference() && this.receiverType.syntheticOuterLocalVariables() != null && currentScope.methodScope().isStatic)) {
generateImplicitLambda(currentScope, codeStream, valueRequired);
return;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java
index 860ebb7cc4..59b5ce6cb9 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java
@@ -1783,9 +1783,6 @@ public ReferenceBinding[] syntheticEnclosingInstanceTypes() {
return null;
return new ReferenceBinding[] {enclosingType};
}
-public SyntheticArgumentBinding[] syntheticOuterLocalVariables() {
- return null; // is null if no enclosing instances are required
-}
MethodBinding[] unResolvedMethods() { // for the MethodVerifier so it doesn't resolve types
return methods();
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java
index 3b1d3a4bb5..df01ceef90 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java
@@ -1558,4 +1558,8 @@ public ReferenceBinding superclass() {
public ReferenceBinding[] superInterfaces() {
return Binding.NO_SUPERINTERFACES;
}
+
+public SyntheticArgumentBinding[] syntheticOuterLocalVariables() {
+ return null; // is null if no enclosing instances are required
+}
}

Back to the top