1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Fri Nov 16 18:27:36 2012 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Sat Nov 17 19:01:03 2012 +0000 1.3 @@ -427,6 +427,60 @@ 1.4 return c != null; 1.5 } 1.6 1.7 + /** 1.8 + * Performs a recursive scan of a type looking for accessibility problems 1.9 + * from current attribution environment 1.10 + */ 1.11 + void checkAccessibleType(Env<AttrContext> env, Type t) { 1.12 + accessibilityChecker.visit(t, env); 1.13 + } 1.14 + 1.15 + /** 1.16 + * Accessibility type-visitor 1.17 + */ 1.18 + Types.SimpleVisitor<Void, Env<AttrContext>> accessibilityChecker = 1.19 + new Types.SimpleVisitor<Void, Env<AttrContext>>() { 1.20 + 1.21 + void visit(List<Type> ts, Env<AttrContext> env) { 1.22 + for (Type t : ts) { 1.23 + visit(t, env); 1.24 + } 1.25 + } 1.26 + 1.27 + public Void visitType(Type t, Env<AttrContext> env) { 1.28 + return null; 1.29 + } 1.30 + 1.31 + @Override 1.32 + public Void visitArrayType(ArrayType t, Env<AttrContext> env) { 1.33 + visit(t.elemtype, env); 1.34 + return null; 1.35 + } 1.36 + 1.37 + @Override 1.38 + public Void visitClassType(ClassType t, Env<AttrContext> env) { 1.39 + visit(t.getTypeArguments(), env); 1.40 + if (!isAccessible(env, t, true)) { 1.41 + accessBase(new AccessError(t.tsym), env.tree.pos(), env.enclClass.sym, t, t.tsym.name, true); 1.42 + } 1.43 + return null; 1.44 + } 1.45 + 1.46 + @Override 1.47 + public Void visitWildcardType(WildcardType t, Env<AttrContext> env) { 1.48 + visit(t.type, env); 1.49 + return null; 1.50 + } 1.51 + 1.52 + @Override 1.53 + public Void visitMethodType(MethodType t, Env<AttrContext> env) { 1.54 + visit(t.getParameterTypes(), env); 1.55 + visit(t.getReturnType(), env); 1.56 + visit(t.getThrownTypes(), env); 1.57 + return null; 1.58 + } 1.59 + }; 1.60 + 1.61 /** Try to instantiate the type of a method so that it fits 1.62 * given type arguments and argument types. If succesful, return 1.63 * the method's instantiated type, else return null. 1.64 @@ -750,10 +804,6 @@ 1.65 public boolean compatible(Type found, Type req, Warner warn) { 1.66 return types.isSubtypeUnchecked(found, inferenceContext.asFree(req, types), warn); 1.67 } 1.68 - 1.69 - public boolean allowBoxing() { 1.70 - return false; 1.71 - } 1.72 } 1.73 1.74 /** 1.75 @@ -770,10 +820,6 @@ 1.76 public boolean compatible(Type found, Type req, Warner warn) { 1.77 return types.isConvertible(found, inferenceContext.asFree(req, types), warn); 1.78 } 1.79 - 1.80 - public boolean allowBoxing() { 1.81 - return true; 1.82 - } 1.83 } 1.84 1.85 /** 1.86 @@ -792,7 +838,7 @@ 1.87 1.88 DeferredAttr.DeferredAttrContext deferredAttrContext; 1.89 1.90 - public MethodResultInfo(Type pt, MethodCheckContext checkContext, DeferredAttr.DeferredAttrContext deferredAttrContext) { 1.91 + public MethodResultInfo(Type pt, CheckContext checkContext, DeferredAttr.DeferredAttrContext deferredAttrContext) { 1.92 attr.super(VAL, pt, checkContext); 1.93 this.deferredAttrContext = deferredAttrContext; 1.94 } 1.95 @@ -809,7 +855,12 @@ 1.96 1.97 @Override 1.98 protected MethodResultInfo dup(Type newPt) { 1.99 - return new MethodResultInfo(newPt, (MethodCheckContext)checkContext, deferredAttrContext); 1.100 + return new MethodResultInfo(newPt, checkContext, deferredAttrContext); 1.101 + } 1.102 + 1.103 + @Override 1.104 + protected ResultInfo dup(CheckContext newContext) { 1.105 + return new MethodResultInfo(pt, newContext, deferredAttrContext); 1.106 } 1.107 } 1.108 1.109 @@ -1020,7 +1071,7 @@ 1.110 Assert.check(sym.kind < AMBIGUOUS); 1.111 try { 1.112 Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes, 1.113 - allowBoxing, useVarargs, Warner.noWarnings); 1.114 + allowBoxing, useVarargs, types.noWarnings); 1.115 if (!operator) 1.116 currentResolutionContext.addApplicableCandidate(sym, mt); 1.117 } catch (InapplicableMethodException ex) { 1.118 @@ -1921,28 +1972,31 @@ 1.119 (typeargtypes == null || !Type.isErroneous(typeargtypes)); 1.120 } 1.121 public List<Type> getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List<Type> argtypes) { 1.122 - if (syms.operatorNames.contains(name)) { 1.123 - return argtypes; 1.124 - } else { 1.125 - Symbol msym = errSym.kind == WRONG_MTH ? 1.126 - ((InapplicableSymbolError)errSym).errCandidate().sym : accessedSym; 1.127 - 1.128 - List<Type> argtypes2 = Type.map(argtypes, 1.129 - deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, msym, currentResolutionContext.step)); 1.130 - 1.131 - if (msym != accessedSym) { 1.132 - //fixup deferred type caches - this 'hack' is required because the symbol 1.133 - //returned by InapplicableSymbolError.access() will hide the candidate 1.134 - //method symbol that can be used for lookups in the speculative cache, 1.135 - //causing problems in Attr.checkId() 1.136 - for (Type t : argtypes) { 1.137 - if (t.hasTag(DEFERRED)) { 1.138 - DeferredType dt = (DeferredType)t; 1.139 - dt.speculativeCache.dupAllTo(msym, accessedSym); 1.140 - } 1.141 + return (syms.operatorNames.contains(name)) ? 1.142 + argtypes : 1.143 + Type.map(argtypes, new ResolveDeferredRecoveryMap(accessedSym)); 1.144 + } 1.145 + 1.146 + class ResolveDeferredRecoveryMap extends DeferredAttr.RecoveryDeferredTypeMap { 1.147 + 1.148 + public ResolveDeferredRecoveryMap(Symbol msym) { 1.149 + deferredAttr.super(AttrMode.SPECULATIVE, msym, currentResolutionContext.step); 1.150 + } 1.151 + 1.152 + @Override 1.153 + protected Type typeOf(DeferredType dt) { 1.154 + Type res = super.typeOf(dt); 1.155 + if (!res.isErroneous()) { 1.156 + switch (TreeInfo.skipParens(dt.tree).getTag()) { 1.157 + case LAMBDA: 1.158 + case REFERENCE: 1.159 + return dt; 1.160 + case CONDEXPR: 1.161 + return res == Type.recoveryType ? 1.162 + dt : res; 1.163 } 1.164 } 1.165 - return argtypes2; 1.166 + return res; 1.167 } 1.168 } 1.169 }; 1.170 @@ -2069,7 +2123,6 @@ 1.171 } else if (allowMethodHandles) { 1.172 MethodSymbol msym = (MethodSymbol)sym; 1.173 if (msym.isSignaturePolymorphic(types)) { 1.174 - env.info.pendingResolutionPhase = BASIC; 1.175 return findPolymorphicSignatureInstance(env, sym, argtypes); 1.176 } 1.177 } 1.178 @@ -2086,7 +2139,7 @@ 1.179 * @param argtypes The required argument types 1.180 */ 1.181 Symbol findPolymorphicSignatureInstance(Env<AttrContext> env, 1.182 - Symbol spMethod, 1.183 + final Symbol spMethod, 1.184 List<Type> argtypes) { 1.185 Type mtype = infer.instantiatePolymorphicSignatureInstance(env, 1.186 (MethodSymbol)spMethod, currentResolutionContext, argtypes); 1.187 @@ -2098,7 +2151,12 @@ 1.188 1.189 // create the desired method 1.190 long flags = ABSTRACT | HYPOTHETICAL | spMethod.flags() & Flags.AccessFlags; 1.191 - Symbol msym = new MethodSymbol(flags, spMethod.name, mtype, spMethod.owner); 1.192 + Symbol msym = new MethodSymbol(flags, spMethod.name, mtype, spMethod.owner) { 1.193 + @Override 1.194 + public Symbol baseSymbol() { 1.195 + return spMethod; 1.196 + } 1.197 + }; 1.198 polymorphicSignatureScope.enter(msym); 1.199 return msym; 1.200 } 1.201 @@ -2707,7 +2765,7 @@ 1.202 } 1.203 if (allowDefaultMethods && c.isInterface() && 1.204 name == names._super && !isStatic(env) && 1.205 - types.isDirectSuperInterface(c.type, env.enclClass.sym)) { 1.206 + types.isDirectSuperInterface(c, env.enclClass.sym)) { 1.207 //this might be a default super call if one of the superinterfaces is 'c' 1.208 for (Type t : pruneInterfaces(env.enclClass.type)) { 1.209 if (t.tsym == c) { 1.210 @@ -3150,7 +3208,7 @@ 1.211 "cant.apply.symbols", 1.212 name == names.init ? KindName.CONSTRUCTOR : absentKind(kind), 1.213 name == names.init ? site.tsym.name : name, 1.214 - argtypes); 1.215 + methodArguments(argtypes)); 1.216 return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(site)); 1.217 } else { 1.218 return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind, pos,