8037789: Surprising more-specific results for lambda bodies with no return expressions
Reviewed-by: mcimadamore, vromero
--- 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);
}
}
}