8175794: Type inference regression after JDK-8078093
authorvromero
Fri, 09 Jun 2017 11:27:03 -0700
changeset 45498 0848a6cbe2a3
parent 45497 cdf29c5063f8
child 45499 16e055f785ef
8175794: Type inference regression after JDK-8078093 Reviewed-by: mcimadamore Contributed-by: maurizio.cimadamore@oracle.com, vicente.romero@oracle.com
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ArgumentAttr.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java
langtools/test/tools/javac/T8175794/MissingReturnConstraintTest.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ArgumentAttr.java	Thu Jun 08 00:11:29 2017 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ArgumentAttr.java	Fri Jun 09 11:27:03 2017 -0700
@@ -556,19 +556,16 @@
         Type overloadCheck(ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) {
             Type mtype = methodType();
             ResultInfo localInfo = resultInfo(resultInfo);
+            Type t;
             if (mtype != null && mtype.hasTag(METHOD) && mtype.isPartial()) {
-                Type t = ((PartiallyInferredMethodType)mtype).check(localInfo);
-                if (!deferredAttrContext.inferenceContext.free(localInfo.pt)) {
-                    speculativeTypes.put(localInfo, t);
-                    return localInfo.check(tree.pos(), t);
-                } else {
-                    return t;
-                }
+                //poly invocation
+                t = ((PartiallyInferredMethodType)mtype).check(localInfo);
             } else {
-                Type t = localInfo.check(tree.pos(), speculativeTree.type);
-                speculativeTypes.put(localInfo, t);
-                return t;
+                //standalone invocation
+                t = localInfo.check(tree.pos(), speculativeTree.type);
             }
+            speculativeTypes.put(localInfo, t);
+            return t;
         }
 
         /**
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java	Thu Jun 08 00:11:29 2017 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java	Fri Jun 09 11:27:03 2017 -0700
@@ -344,9 +344,8 @@
                     //inline logic from Attr.checkMethod - if unchecked conversion was required, erase
                     //return type _after_ resolution, and check against target
                     ret = types.erasure(ret);
-                    resultInfo.check(env.tree, ret);
                 }
-                return ret;
+                return resultInfo.check(env.tree, ret);
             } catch (InferenceException ex) {
                 resultInfo.checkContext.report(null, ex.getDiagnostic());
                 Assert.error(); //cannot get here (the above should throw)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T8175794/MissingReturnConstraintTest.java	Fri Jun 09 11:27:03 2017 -0700
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. 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 8175794
+ * @summary Type inference regression after JDK-8078093
+ * @compile MissingReturnConstraintTest.java
+ */
+
+import java.util.concurrent.ExecutorService;
+
+public abstract class MissingReturnConstraintTest {
+    void f(ExecutorService s) {
+        s.submit(() -> run(() -> {}));
+    }
+
+    abstract <E extends Throwable> void run(ThrowableRunnable<E> action) throws E;
+
+    public interface ThrowableRunnable<T extends Throwable> {
+        void run() throws T;
+    }
+}