8037789: Surprising more-specific results for lambda bodies with no return expressions
authordlsmith
Fri, 08 Jan 2016 12:29:02 -0700
changeset 34992 eaba62b5d8e2
parent 34991 ff8be37d1164
child 34993 5e0e33e23855
8037789: Surprising more-specific results for lambda bodies with no return expressions Reviewed-by: mcimadamore, vromero
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Jan 08 17:14:10 2016 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Jan 08 12:29:02 2016 -0700
@@ -1219,18 +1219,21 @@
                             result &= true;
                         } else if (ret_t.hasTag(VOID)) {
                             result &= false;
-                        } else if (unrelatedFunctionalInterfaces(ret_t, ret_s)) {
-                            for (JCExpression expr : lambdaResults(tree)) {
-                                result &= functionalInterfaceMostSpecific(ret_t, ret_s, expr);
+                        } else {
+                            List<JCExpression> lambdaResults = lambdaResults(tree);
+                            if (!lambdaResults.isEmpty() && unrelatedFunctionalInterfaces(ret_t, ret_s)) {
+                                for (JCExpression expr : lambdaResults) {
+                                    result &= functionalInterfaceMostSpecific(ret_t, ret_s, expr);
+                                }
+                            } else if (!lambdaResults.isEmpty() && ret_t.isPrimitive() != ret_s.isPrimitive()) {
+                                for (JCExpression expr : lambdaResults) {
+                                    boolean retValIsPrimitive = expr.isStandalone() && expr.type.isPrimitive();
+                                    result &= (retValIsPrimitive == ret_t.isPrimitive()) &&
+                                            (retValIsPrimitive != ret_s.isPrimitive());
+                                }
+                            } else {
+                                result &= compatibleBySubtyping(ret_t, ret_s);
                             }
-                        } else if (ret_t.isPrimitive() != ret_s.isPrimitive()) {
-                            for (JCExpression expr : lambdaResults(tree)) {
-                                boolean retValIsPrimitive = expr.isStandalone() && expr.type.isPrimitive();
-                                result &= (retValIsPrimitive == ret_t.isPrimitive()) &&
-                                          (retValIsPrimitive != ret_s.isPrimitive());
-                            }
-                        } else {
-                            result &= compatibleBySubtyping(ret_t, ret_s);
                         }
                     }
                 }