1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Tue Sep 25 11:53:18 2012 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Tue Sep 25 11:55:34 2012 +0100 1.3 @@ -31,6 +31,8 @@ 1.4 import com.sun.tools.javac.code.Symbol.*; 1.5 import com.sun.tools.javac.comp.Attr.ResultInfo; 1.6 import com.sun.tools.javac.comp.Check.CheckContext; 1.7 +import com.sun.tools.javac.comp.Infer.InferenceContext; 1.8 +import com.sun.tools.javac.comp.Infer.InferenceContext.FreeTypeListener; 1.9 import com.sun.tools.javac.comp.Resolve.MethodResolutionContext.Candidate; 1.10 import com.sun.tools.javac.jvm.*; 1.11 import com.sun.tools.javac.tree.*; 1.12 @@ -586,7 +588,7 @@ 1.13 boolean allowBoxing, 1.14 boolean useVarargs, 1.15 Warner warn) { 1.16 - checkRawArgumentsAcceptable(env, List.<Type>nil(), argtypes, formals, 1.17 + checkRawArgumentsAcceptable(env, infer.emptyContext, argtypes, formals, 1.18 allowBoxing, useVarargs, warn, resolveHandler); 1.19 } 1.20 1.21 @@ -606,8 +608,8 @@ 1.22 * 1.23 * A method check handler (see above) is used in order to report errors. 1.24 */ 1.25 - List<Type> checkRawArgumentsAcceptable(Env<AttrContext> env, 1.26 - List<Type> undetvars, 1.27 + void checkRawArgumentsAcceptable(final Env<AttrContext> env, 1.28 + final Infer.InferenceContext inferenceContext, 1.29 List<Type> argtypes, 1.30 List<Type> formals, 1.31 boolean allowBoxing, 1.32 @@ -623,7 +625,7 @@ 1.33 } 1.34 1.35 while (argtypes.nonEmpty() && formals.head != varargsFormal) { 1.36 - ResultInfo resultInfo = methodCheckResult(formals.head, allowBoxing, false, undetvars, handler, warn); 1.37 + ResultInfo resultInfo = methodCheckResult(formals.head, allowBoxing, false, inferenceContext, handler, warn); 1.38 checkedArgs.append(resultInfo.check(env.tree.pos(), argtypes.head)); 1.39 argtypes = argtypes.tail; 1.40 formals = formals.tail; 1.41 @@ -638,17 +640,29 @@ 1.42 //the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5) 1.43 Type elt = types.elemtype(varargsFormal); 1.44 while (argtypes.nonEmpty()) { 1.45 - ResultInfo resultInfo = methodCheckResult(elt, allowBoxing, true, undetvars, handler, warn); 1.46 + ResultInfo resultInfo = methodCheckResult(elt, allowBoxing, true, inferenceContext, handler, warn); 1.47 checkedArgs.append(resultInfo.check(env.tree.pos(), argtypes.head)); 1.48 argtypes = argtypes.tail; 1.49 } 1.50 //check varargs element type accessibility 1.51 - if (undetvars.isEmpty() && !isAccessible(env, elt)) { 1.52 + varargsAccessible(env, elt, handler, inferenceContext); 1.53 + } 1.54 + } 1.55 + 1.56 + void varargsAccessible(final Env<AttrContext> env, final Type t, final Resolve.MethodCheckHandler handler, final InferenceContext inferenceContext) { 1.57 + if (inferenceContext.free(t)) { 1.58 + inferenceContext.addFreeTypeListener(List.of(t), new FreeTypeListener() { 1.59 + @Override 1.60 + public void typesInferred(InferenceContext inferenceContext) { 1.61 + varargsAccessible(env, inferenceContext.asInstType(t, types), handler, inferenceContext); 1.62 + } 1.63 + }); 1.64 + } else { 1.65 + if (!isAccessible(env, t)) { 1.66 Symbol location = env.enclClass.sym; 1.67 - throw handler.inaccessibleVarargs(location, elt); 1.68 + throw handler.inaccessibleVarargs(location, t); 1.69 } 1.70 } 1.71 - return checkedArgs.toList(); 1.72 } 1.73 1.74 /** 1.75 @@ -659,13 +673,13 @@ 1.76 1.77 MethodCheckHandler handler; 1.78 boolean useVarargs; 1.79 - List<Type> undetvars; 1.80 + Infer.InferenceContext inferenceContext; 1.81 Warner rsWarner; 1.82 1.83 - public MethodCheckContext(MethodCheckHandler handler, boolean useVarargs, List<Type> undetvars, Warner rsWarner) { 1.84 + public MethodCheckContext(MethodCheckHandler handler, boolean useVarargs, Infer.InferenceContext inferenceContext, Warner rsWarner) { 1.85 this.handler = handler; 1.86 this.useVarargs = useVarargs; 1.87 - this.undetvars = undetvars; 1.88 + this.inferenceContext = inferenceContext; 1.89 this.rsWarner = rsWarner; 1.90 } 1.91 1.92 @@ -676,6 +690,10 @@ 1.93 public Warner checkWarner(DiagnosticPosition pos, Type found, Type req) { 1.94 return rsWarner; 1.95 } 1.96 + 1.97 + public InferenceContext inferenceContext() { 1.98 + return inferenceContext; 1.99 + } 1.100 } 1.101 1.102 /** 1.103 @@ -684,12 +702,12 @@ 1.104 */ 1.105 class StrictMethodContext extends MethodCheckContext { 1.106 1.107 - public StrictMethodContext(MethodCheckHandler handler, boolean useVarargs, List<Type> undetvars, Warner rsWarner) { 1.108 - super(handler, useVarargs, undetvars, rsWarner); 1.109 + public StrictMethodContext(MethodCheckHandler handler, boolean useVarargs, Infer.InferenceContext inferenceContext, Warner rsWarner) { 1.110 + super(handler, useVarargs, inferenceContext, rsWarner); 1.111 } 1.112 1.113 public boolean compatible(Type found, Type req, Warner warn) { 1.114 - return types.isSubtypeUnchecked(found, infer.asUndetType(req, undetvars), warn); 1.115 + return types.isSubtypeUnchecked(found, inferenceContext.asFree(req, types), warn); 1.116 } 1.117 } 1.118 1.119 @@ -699,12 +717,12 @@ 1.120 */ 1.121 class LooseMethodContext extends MethodCheckContext { 1.122 1.123 - public LooseMethodContext(MethodCheckHandler handler, boolean useVarargs, List<Type> undetvars, Warner rsWarner) { 1.124 - super(handler, useVarargs, undetvars, rsWarner); 1.125 + public LooseMethodContext(MethodCheckHandler handler, boolean useVarargs, Infer.InferenceContext inferenceContext, Warner rsWarner) { 1.126 + super(handler, useVarargs, inferenceContext, rsWarner); 1.127 } 1.128 1.129 public boolean compatible(Type found, Type req, Warner warn) { 1.130 - return types.isConvertible(found, infer.asUndetType(req, undetvars), warn); 1.131 + return types.isConvertible(found, inferenceContext.asFree(req, types), warn); 1.132 } 1.133 } 1.134 1.135 @@ -712,10 +730,10 @@ 1.136 * Create a method check context to be used during method applicability check 1.137 */ 1.138 ResultInfo methodCheckResult(Type to, boolean allowBoxing, boolean useVarargs, 1.139 - List<Type> undetvars, MethodCheckHandler methodHandler, Warner rsWarner) { 1.140 + Infer.InferenceContext inferenceContext, MethodCheckHandler methodHandler, Warner rsWarner) { 1.141 MethodCheckContext checkContext = allowBoxing ? 1.142 - new LooseMethodContext(methodHandler, useVarargs, undetvars, rsWarner) : 1.143 - new StrictMethodContext(methodHandler, useVarargs, undetvars, rsWarner); 1.144 + new LooseMethodContext(methodHandler, useVarargs, inferenceContext, rsWarner) : 1.145 + new StrictMethodContext(methodHandler, useVarargs, inferenceContext, rsWarner); 1.146 return attr.new ResultInfo(VAL, to, checkContext) { 1.147 @Override 1.148 protected Type check(DiagnosticPosition pos, Type found) { 1.149 @@ -735,16 +753,13 @@ 1.150 this.diags = diags; 1.151 } 1.152 InapplicableMethodException setMessage() { 1.153 - this.diagnostic = null; 1.154 - return this; 1.155 + return setMessage((JCDiagnostic)null); 1.156 } 1.157 InapplicableMethodException setMessage(String key) { 1.158 - this.diagnostic = key != null ? diags.fragment(key) : null; 1.159 - return this; 1.160 + return setMessage(key != null ? diags.fragment(key) : null); 1.161 } 1.162 InapplicableMethodException setMessage(String key, Object... args) { 1.163 - this.diagnostic = key != null ? diags.fragment(key, args) : null; 1.164 - return this; 1.165 + return setMessage(key != null ? diags.fragment(key, args) : null); 1.166 } 1.167 InapplicableMethodException setMessage(JCDiagnostic diag) { 1.168 this.diagnostic = diag;