src/share/classes/com/sun/tools/javac/comp/Infer.java

changeset 820
2d5aff89aaa3
parent 798
4868a36f6fd8
child 828
19c900c703c6
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java	Thu Jan 13 21:28:38 2011 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java	Fri Jan 14 09:45:04 2011 +0000
     1.3 @@ -27,6 +27,7 @@
     1.4  
     1.5  import com.sun.tools.javac.tree.JCTree;
     1.6  import com.sun.tools.javac.tree.JCTree.JCTypeCast;
     1.7 +import com.sun.tools.javac.tree.TreeInfo;
     1.8  import com.sun.tools.javac.util.*;
     1.9  import com.sun.tools.javac.util.List;
    1.10  import com.sun.tools.javac.code.*;
    1.11 @@ -538,43 +539,39 @@
    1.12  
    1.13      /**
    1.14       * Compute a synthetic method type corresponding to the requested polymorphic
    1.15 -     * method signature. If no explicit return type is supplied, a provisional
    1.16 -     * return type is computed (just Object in case of non-transitional 292)
    1.17 +     * method signature. The target return type is computed from the immediately
    1.18 +     * enclosing scope surrounding the polymorphic-signature call.
    1.19       */
    1.20      Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env, Type site,
    1.21                                              Name name,
    1.22                                              MethodSymbol spMethod,  // sig. poly. method or null if none
    1.23 -                                            List<Type> argtypes,
    1.24 -                                            List<Type> typeargtypes) {
    1.25 +                                            List<Type> argtypes) {
    1.26          final Type restype;
    1.27 -        if (rs.allowTransitionalJSR292 && typeargtypes.nonEmpty()) {
    1.28 -            restype = typeargtypes.head;
    1.29 -        } else {
    1.30 -            //The return type for a polymorphic signature call is computed from
    1.31 -            //the enclosing tree E, as follows: if E is a cast, then use the
    1.32 -            //target type of the cast expression as a return type; if E is an
    1.33 -            //expression statement, the return type is 'void' - otherwise the
    1.34 -            //return type is simply 'Object'. A correctness check ensures that
    1.35 -            //env.next refers to the lexically enclosing environment in which
    1.36 -            //the polymorphic signature call environment is nested.
    1.37  
    1.38 -            switch (env.next.tree.getTag()) {
    1.39 -                case JCTree.TYPECAST:
    1.40 -                    JCTypeCast castTree = (JCTypeCast)env.next.tree;
    1.41 -                    restype = (castTree.expr == env.tree) ?
    1.42 -                        castTree.clazz.type :
    1.43 -                        syms.objectType;
    1.44 -                    break;
    1.45 -                case JCTree.EXEC:
    1.46 -                    JCTree.JCExpressionStatement execTree =
    1.47 -                            (JCTree.JCExpressionStatement)env.next.tree;
    1.48 -                    restype = (execTree.expr == env.tree) ?
    1.49 -                        syms.voidType :
    1.50 -                        syms.objectType;
    1.51 -                    break;
    1.52 -                default:
    1.53 -                    restype = syms.objectType;
    1.54 -            }
    1.55 +        //The return type for a polymorphic signature call is computed from
    1.56 +        //the enclosing tree E, as follows: if E is a cast, then use the
    1.57 +        //target type of the cast expression as a return type; if E is an
    1.58 +        //expression statement, the return type is 'void' - otherwise the
    1.59 +        //return type is simply 'Object'. A correctness check ensures that
    1.60 +        //env.next refers to the lexically enclosing environment in which
    1.61 +        //the polymorphic signature call environment is nested.
    1.62 +
    1.63 +        switch (env.next.tree.getTag()) {
    1.64 +            case JCTree.TYPECAST:
    1.65 +                JCTypeCast castTree = (JCTypeCast)env.next.tree;
    1.66 +                restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
    1.67 +                    castTree.clazz.type :
    1.68 +                    syms.objectType;
    1.69 +                break;
    1.70 +            case JCTree.EXEC:
    1.71 +                JCTree.JCExpressionStatement execTree =
    1.72 +                        (JCTree.JCExpressionStatement)env.next.tree;
    1.73 +                restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
    1.74 +                    syms.voidType :
    1.75 +                    syms.objectType;
    1.76 +                break;
    1.77 +            default:
    1.78 +                restype = syms.objectType;
    1.79          }
    1.80  
    1.81          List<Type> paramtypes = Type.map(argtypes, implicitArgType);

mercurial