diff -r 9bfb0e6fd526 -r 493ecc8111ba src/share/classes/com/sun/tools/javac/comp/Infer.java --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Wed Oct 13 17:52:29 2010 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Mon Oct 18 19:14:36 2010 +0100 @@ -553,12 +553,24 @@ //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'. - switch (env.outer.tree.getTag()) { + //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 JCTree.TYPECAST: - restype = ((JCTypeCast)env.outer.tree).clazz.type; break; + JCTypeCast castTree = (JCTypeCast)env.next.tree; + restype = (castTree.expr == env.tree) ? + castTree.clazz.type : + syms.objectType; + break; case JCTree.EXEC: - restype = syms.voidType; break; + JCTree.JCExpressionStatement execTree = + (JCTree.JCExpressionStatement)env.next.tree; + restype = (execTree.expr == env.tree) ? + syms.voidType : + syms.objectType; + break; default: restype = syms.objectType; }