8173456: com.sun.tools.javac.util.Assert.error during code compilation
authorsadayapalam
Mon, 06 Feb 2017 13:12:30 +0530
changeset 43582 a6c58d4cb05b
parent 43581 af18ebffc685
child 43583 d16e490ec827
8173456: com.sun.tools.javac.util.Assert.error during code compilation Reviewed-by: mcimadamore
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
langtools/test/tools/javac/lambda/MethodReferenceNoThisTest.java
langtools/test/tools/javac/lambda/MethodReferenceNoThisTest.out
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Sat Feb 04 14:05:08 2017 -0500
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Feb 06 13:12:30 2017 +0530
@@ -2947,6 +2947,14 @@
                 return;
             }
 
+            if (!env.info.isSpeculative && that.getMode() == JCMemberReference.ReferenceMode.NEW) {
+                Type enclosingType = exprType.getEnclosingType();
+                if (enclosingType != null && enclosingType.hasTag(CLASS)) {
+                    // Check for the existence of an apropriate outer instance
+                    rs.resolveImplicitThis(that.pos(), env, exprType);
+                }
+            }
+
             if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.CHECK) {
 
                 if (that.getMode() == ReferenceMode.INVOKE &&
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/MethodReferenceNoThisTest.java	Mon Feb 06 13:12:30 2017 +0530
@@ -0,0 +1,31 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8173456
+ * @summary com.sun.tools.javac.util.Assert.error during code compilation
+ * @compile/fail/ref=MethodReferenceNoThisTest.out -XDrawDiagnostics MethodReferenceNoThisTest.java
+ */
+
+import java.util.function.Function;
+
+abstract class MethodReferenceNoThisTest_Base {
+  protected MethodReferenceNoThisTest_Base(Function<MethodReferenceNoThisTest_Base, MethodReferenceNoThisTest_AV> x) {}
+}
+
+abstract class MethodReferenceNoThisTest_AV {
+    MethodReferenceNoThisTest_AV(MethodReferenceNoThisTest_Base b) {
+    }
+}
+
+public class MethodReferenceNoThisTest extends MethodReferenceNoThisTest_Base {
+
+    public MethodReferenceNoThisTest() {
+        super(V::new);
+    }
+
+    private class V extends MethodReferenceNoThisTest_AV {
+
+        V(MethodReferenceNoThisTest_Base b) {
+            super(b);
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/MethodReferenceNoThisTest.out	Mon Feb 06 13:12:30 2017 +0530
@@ -0,0 +1,2 @@
+MethodReferenceNoThisTest.java:22:15: compiler.err.cant.ref.before.ctor.called: this
+1 error
\ No newline at end of file