--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java Tue Mar 15 14:50:00 2016 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java Thu Mar 24 11:21:37 2016 +0100
@@ -560,30 +560,37 @@
List<Type> argtypes) {
final Type restype;
- //The return type for a polymorphic signature call is computed from
- //the enclosing tree E, as follows: if E is a cast, then use the
- //target type of the cast expression as a return type; if E is an
- //expression statement, the return type is 'void' - otherwise the
- //return type is simply 'Object'. A correctness check ensures that
- //env.next refers to the lexically enclosing environment in which
- //the polymorphic signature call environment is nested.
+ if (spMethod == null || types.isSameType(spMethod.getReturnType(), syms.objectType, true)) {
+ // The return type of the polymorphic signature is polymorphic,
+ // and is computed from the enclosing tree E, as follows:
+ // if E is a cast, then use the target type of the cast expression
+ // as a return type; if E is an expression statement, the return
+ // type is 'void'; otherwise
+ // the return type is simply 'Object'. A correctness check ensures
+ // that env.next refers to the lexically enclosing environment in
+ // which the polymorphic signature call environment is nested.
- switch (env.next.tree.getTag()) {
- case TYPECAST:
- JCTypeCast castTree = (JCTypeCast)env.next.tree;
- restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
- castTree.clazz.type :
- syms.objectType;
- break;
- case EXEC:
- JCTree.JCExpressionStatement execTree =
- (JCTree.JCExpressionStatement)env.next.tree;
- restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
- syms.voidType :
- syms.objectType;
- break;
- default:
- restype = syms.objectType;
+ switch (env.next.tree.getTag()) {
+ case TYPECAST:
+ JCTypeCast castTree = (JCTypeCast)env.next.tree;
+ restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
+ castTree.clazz.type :
+ syms.objectType;
+ break;
+ case EXEC:
+ JCTree.JCExpressionStatement execTree =
+ (JCTree.JCExpressionStatement)env.next.tree;
+ restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
+ syms.voidType :
+ syms.objectType;
+ break;
+ default:
+ restype = syms.objectType;
+ }
+ } else {
+ // The return type of the polymorphic signature is fixed
+ // (not polymorphic)
+ restype = spMethod.getReturnType();
}
List<Type> paramtypes = argtypes.map(new ImplicitArgType(spMethod, resolveContext.step));