1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Fri Apr 09 15:39:39 2010 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Wed Apr 14 12:23:29 2010 +0100 1.3 @@ -375,6 +375,8 @@ 1.4 Type checkType(DiagnosticPosition pos, Type found, Type req) { 1.5 if (req.tag == ERROR) 1.6 return req; 1.7 + if (found.tag == FORALL) 1.8 + return instantiatePoly(pos, (ForAll)found, req, convertWarner(pos, found, req)); 1.9 if (req.tag == NONE) 1.10 return found; 1.11 if (types.isAssignable(found, req, convertWarner(pos, found, req))) 1.12 @@ -392,33 +394,6 @@ 1.13 return typeError(pos, diags.fragment("incompatible.types"), found, req); 1.14 } 1.15 1.16 - Type checkReturnType(DiagnosticPosition pos, Type found, Type req) { 1.17 - if (found.tag == FORALL) { 1.18 - try { 1.19 - return instantiatePoly(pos, (ForAll) found, req, convertWarner(pos, found, req)); 1.20 - } catch (Infer.NoInstanceException ex) { 1.21 - if (ex.isAmbiguous) { 1.22 - JCDiagnostic d = ex.getDiagnostic(); 1.23 - log.error(pos, 1.24 - "undetermined.type" + (d != null ? ".1" : ""), 1.25 - found, d); 1.26 - return types.createErrorType(req); 1.27 - } else { 1.28 - JCDiagnostic d = ex.getDiagnostic(); 1.29 - return typeError(pos, 1.30 - diags.fragment("incompatible.types" + (d != null ? ".1" : ""), d), 1.31 - found, req); 1.32 - } 1.33 - } catch (Infer.InvalidInstanceException ex) { 1.34 - JCDiagnostic d = ex.getDiagnostic(); 1.35 - log.error(pos, "invalid.inferred.types", ((ForAll)found).tvars, d); 1.36 - return types.createErrorType(req); 1.37 - } 1.38 - } else { 1.39 - return checkType(pos, found, req); 1.40 - } 1.41 - } 1.42 - 1.43 /** Instantiate polymorphic type to some prototype, unless 1.44 * prototype is `anyPoly' in which case polymorphic type 1.45 * is returned unchanged. 1.46 @@ -432,9 +407,28 @@ 1.47 } else if (pt.tag == ERROR) { 1.48 return pt; 1.49 } else { 1.50 - return infer.instantiateExpr(t, pt, warn); 1.51 + try { 1.52 + return infer.instantiateExpr(t, pt, warn); 1.53 + } catch (Infer.NoInstanceException ex) { 1.54 + if (ex.isAmbiguous) { 1.55 + JCDiagnostic d = ex.getDiagnostic(); 1.56 + log.error(pos, 1.57 + "undetermined.type" + (d!=null ? ".1" : ""), 1.58 + t, d); 1.59 + return types.createErrorType(pt); 1.60 + } else { 1.61 + JCDiagnostic d = ex.getDiagnostic(); 1.62 + return typeError(pos, 1.63 + diags.fragment("incompatible.types" + (d!=null ? ".1" : ""), d), 1.64 + t, pt); 1.65 + } 1.66 + } catch (Infer.InvalidInstanceException ex) { 1.67 + JCDiagnostic d = ex.getDiagnostic(); 1.68 + log.error(pos, "invalid.inferred.types", t.tvars, d); 1.69 + return types.createErrorType(pt); 1.70 + } 1.71 } 1.72 - } 1.73 + } 1.74 1.75 /** Check that a given type can be cast to a given target type. 1.76 * Return the result of the cast. 1.77 @@ -557,29 +551,6 @@ 1.78 return t; 1.79 } 1.80 1.81 - /** Check that type is a valid type for a new expression. If the type contains 1.82 - * some uninferred type variables, instantiate them exploiting the expected 1.83 - * type. 1.84 - * 1.85 - * @param pos Position to be used for error reporting. 1.86 - * @param t The type to be checked. 1.87 - * @param noBounds True if type bounds are illegal here. 1.88 - * @param pt Expected type (used with diamond operator) 1.89 - */ 1.90 - Type checkNewClassType(DiagnosticPosition pos, Type t, boolean noBounds, Type pt) { 1.91 - if (t.tag == FORALL) { 1.92 - try { 1.93 - t = instantiatePoly(pos, (ForAll)t, pt, Warner.noWarnings); 1.94 - } 1.95 - catch (Infer.NoInstanceException ex) { 1.96 - JCDiagnostic d = ex.getDiagnostic(); 1.97 - log.error(pos, "cant.apply.diamond", t.getTypeArguments(), d); 1.98 - return types.createErrorType(pt); 1.99 - } 1.100 - } 1.101 - return checkClassType(pos, t, noBounds); 1.102 - } 1.103 - 1.104 /** Check that type is a reifiable class, interface or array type. 1.105 * @param pos Position to be used for error reporting. 1.106 * @param t The type to be checked. 1.107 @@ -936,8 +907,7 @@ 1.108 } 1.109 1.110 checkCapture(tree); 1.111 - } 1.112 - if (tree.type.tag == CLASS || tree.type.tag == FORALL) { 1.113 + 1.114 // Check that this type is either fully parameterized, or 1.115 // not parameterized at all. 1.116 if (tree.type.getEnclosingType().isRaw())