src/share/classes/com/sun/tools/javac/code/Types.java

changeset 196
1ca2dc8584e1
parent 187
e157bd68dfc5
child 202
3b2c55b7bd01
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Tue Jan 20 17:49:09 2009 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Tue Jan 20 17:49:49 2009 +0000
     1.3 @@ -2933,32 +2933,16 @@
     1.4       * Language Specification, Third Ed. (8.4.5)</a>
     1.5       */
     1.6      public boolean returnTypeSubstitutable(Type r1, Type r2) {
     1.7 +        return returnTypeSubstitutable(r1, r2, Warner.noWarnings);
     1.8 +    }
     1.9 +    //where
    1.10 +    public boolean returnTypeSubstitutable(Type r1, Type r2, Warner warner) {
    1.11          if (hasSameArgs(r1, r2))
    1.12 -            return resultSubtype(r1, r2, Warner.noWarnings);
    1.13 +            return resultSubtype(r1, r2, warner);
    1.14          else
    1.15              return covariantReturnType(r1.getReturnType(),
    1.16 -                                       erasure(r2.getReturnType()),
    1.17 -                                       Warner.noWarnings);
    1.18 -    }
    1.19 -
    1.20 -    public boolean returnTypeSubstitutable(Type r1,
    1.21 -                                           Type r2, Type r2res,
    1.22 -                                           Warner warner) {
    1.23 -        if (isSameType(r1.getReturnType(), r2res))
    1.24 -            return true;
    1.25 -        if (r1.getReturnType().isPrimitive() || r2res.isPrimitive())
    1.26 -            return false;
    1.27 -
    1.28 -        if (hasSameArgs(r1, r2))
    1.29 -            return covariantReturnType(r1.getReturnType(), r2res, warner);
    1.30 -        if (!source.allowCovariantReturns())
    1.31 -            return false;
    1.32 -        if (isSubtypeUnchecked(r1.getReturnType(), r2res, warner))
    1.33 -            return true;
    1.34 -        if (!isSubtype(r1.getReturnType(), erasure(r2res)))
    1.35 -            return false;
    1.36 -        warner.warnUnchecked();
    1.37 -        return true;
    1.38 +                                       r2.getReturnType(),
    1.39 +                                       warner);
    1.40      }
    1.41  
    1.42      /**
    1.43 @@ -2966,12 +2950,24 @@
    1.44       * method that returns s?
    1.45       */
    1.46      public boolean covariantReturnType(Type t, Type s, Warner warner) {
    1.47 -        return
    1.48 -            isSameType(t, s) ||
    1.49 -            source.allowCovariantReturns() &&
    1.50 +        //are return types identical?
    1.51 +        if (isSameType(t, s))
    1.52 +            return true;
    1.53 +        //if t and s are both reference types...
    1.54 +        else if(source.allowCovariantReturns() &&
    1.55              !t.isPrimitive() &&
    1.56 -            !s.isPrimitive() &&
    1.57 -            isAssignable(t, s, warner);
    1.58 +            !s.isPrimitive()) {
    1.59 +            //check that t is some unchecked subtype of s
    1.60 +            if (isSubtypeUnchecked(t, s, warner))
    1.61 +                return true;
    1.62 +            //otherwise check that t = |s|
    1.63 +            else if (isSameType(t, erasure(s))) {
    1.64 +                warner.warnUnchecked();
    1.65 +                return true;
    1.66 +            }
    1.67 +        }
    1.68 +        //otherwise t is not return type substitutable for s
    1.69 +        return false;
    1.70      }
    1.71      // </editor-fold>
    1.72  

mercurial