8210483: AssertionError in DeferredAttr at setOverloadKind caused by JDK-8203679
authorcushon
Mon, 10 Sep 2018 16:59:41 -0700
changeset 51721 96b76dca2be8
parent 51720 b7bfd64e43a6
child 51722 49efbe629159
8210483: AssertionError in DeferredAttr at setOverloadKind caused by JDK-8203679 Reviewed-by: mcimadamore, vromero
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ArgumentAttr.java
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java
test/langtools/tools/javac/lambda/methodReference/MethodRefStuck.java
test/langtools/tools/javac/lambda/methodReference/MethodRefStuck.out
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ArgumentAttr.java	Wed Sep 12 17:45:22 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ArgumentAttr.java	Mon Sep 10 16:59:41 2018 -0700
@@ -280,8 +280,9 @@
         if (!res.kind.isResolutionError()) {
             tree.sym = res;
         }
-        if (res.kind.isResolutionTargetError() ||
-                res.type != null && res.type.hasTag(FORALL) ||
+        if (res.kind.isResolutionTargetError()) {
+             tree.setOverloadKind(JCMemberReference.OverloadKind.ERROR);
+        } else if (res.type != null && res.type.hasTag(FORALL) ||
                 (res.flags() & Flags.VARARGS) != 0 ||
                 (TreeInfo.isStaticSelector(exprTree, tree.name.table.names) &&
                 exprTree.type.isRaw() && !exprTree.type.hasTag(ARRAY))) {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Wed Sep 12 17:45:22 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Mon Sep 10 16:59:41 2018 -0700
@@ -169,7 +169,7 @@
                         @Override
                         public void setOverloadKind(OverloadKind overloadKind) {
                             OverloadKind previous = t.getOverloadKind();
-                            if (previous == null) {
+                            if (previous == null || previous == OverloadKind.ERROR) {
                                 t.setOverloadKind(overloadKind);
                             } else {
                                 Assert.check(previous == overloadKind);
@@ -1240,7 +1240,7 @@
             Type descType = types.findDescriptorType(pt);
             List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes());
             if (freeArgVars.nonEmpty() &&
-                    tree.getOverloadKind() == JCMemberReference.OverloadKind.OVERLOADED) {
+                    tree.getOverloadKind() != JCMemberReference.OverloadKind.UNOVERLOADED) {
                 stuckVars.addAll(freeArgVars);
                 depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType()));
             }
@@ -1305,7 +1305,7 @@
         @Override
         public void visitReference(JCMemberReference tree) {
             super.visitReference(tree);
-            if (tree.getOverloadKind() == JCMemberReference.OverloadKind.OVERLOADED) {
+            if (tree.getOverloadKind() != JCMemberReference.OverloadKind.UNOVERLOADED) {
                 stuck = true;
             }
         }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java	Wed Sep 12 17:45:22 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java	Mon Sep 10 16:59:41 2018 -0700
@@ -2217,7 +2217,8 @@
 
         public enum OverloadKind {
             OVERLOADED,
-            UNOVERLOADED
+            UNOVERLOADED,
+            ERROR
         }
 
         /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/lambda/methodReference/MethodRefStuck.java	Mon Sep 10 16:59:41 2018 -0700
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2018, Google LLC. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8210483
+ * @summary AssertionError in DeferredAttr at setOverloadKind caused by JDK-8203679
+ * @compile/fail/ref=MethodRefStuck.out -XDrawDiagnostics MethodRefStuck.java
+ */
+
+import java.util.Optional;
+import java.util.stream.Stream;
+
+public abstract class MethodRefStuck {
+  public static void main(Stream<String> xs, Optional<String> x) {
+    xs.map(
+        c -> {
+          return new I(x.map(c::equals));
+        });
+  }
+
+  static class I {
+    I(boolean i) {}
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/lambda/methodReference/MethodRefStuck.out	Mon Sep 10 16:59:41 2018 -0700
@@ -0,0 +1,2 @@
+MethodRefStuck.java:38:18: compiler.err.cant.apply.symbol: kindname.constructor, I, boolean, java.util.Optional<java.lang.Boolean>, kindname.class, MethodRefStuck.I, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.infer.no.conforming.instance.exists: U, java.util.Optional<U>, boolean))
+1 error