Wed, 07 May 2014 21:33:15 -0700
Merge
1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Wed May 07 10:59:12 2014 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Wed May 07 21:33:15 2014 -0700 1.3 @@ -43,6 +43,7 @@ 1.4 import com.sun.tools.javac.comp.Enter; 1.5 import com.sun.tools.javac.comp.Env; 1.6 import com.sun.tools.javac.jvm.ClassReader; 1.7 +import com.sun.tools.javac.tree.JCTree; 1.8 import com.sun.tools.javac.util.*; 1.9 import static com.sun.tools.javac.code.BoundKind.*; 1.10 import static com.sun.tools.javac.code.Flags.*; 1.11 @@ -305,8 +306,8 @@ 1.12 } 1.13 1.14 /** 1.15 - * Is t a subtype of or convertiable via boxing/unboxing 1.16 - * convertions to s? 1.17 + * Is t a subtype of or convertible via boxing/unboxing 1.18 + * conversions to s? 1.19 */ 1.20 public boolean isConvertible(Type t, Type s) { 1.21 return isConvertible(t, s, noWarnings); 1.22 @@ -1934,6 +1935,17 @@ 1.23 * @param sym a symbol 1.24 */ 1.25 public Type asSuper(Type t, Symbol sym) { 1.26 + /* Some examples: 1.27 + * 1.28 + * (Enum<E>, Comparable) => Comparable<E> 1.29 + * (c.s.s.d.AttributeTree.ValueKind, Enum) => Enum<c.s.s.d.AttributeTree.ValueKind> 1.30 + * (c.s.s.t.ExpressionTree, c.s.s.t.Tree) => c.s.s.t.Tree 1.31 + * (j.u.List<capture#160 of ? extends c.s.s.d.DocTree>, Iterable) => 1.32 + * Iterable<capture#160 of ? extends c.s.s.d.DocTree> 1.33 + */ 1.34 + if (sym.type == syms.objectType) { //optimization 1.35 + return syms.objectType; 1.36 + } 1.37 return asSuper.visit(t, sym); 1.38 } 1.39 // where 1.40 @@ -3869,9 +3881,11 @@ 1.41 } 1.42 return buf.reverse(); 1.43 } 1.44 + 1.45 public Type capture(Type t) { 1.46 - if (!t.hasTag(CLASS)) 1.47 + if (!t.hasTag(CLASS)) { 1.48 return t; 1.49 + } 1.50 if (t.getEnclosingType() != Type.noType) { 1.51 Type capturedEncl = capture(t.getEnclosingType()); 1.52 if (capturedEncl != t.getEnclosingType()) {
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Wed May 07 10:59:12 2014 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Wed May 07 21:33:15 2014 -0700 2.3 @@ -510,6 +510,11 @@ 2.4 public DeferredAttrContext deferredAttrContext() { 2.5 return deferredAttr.emptyDeferredAttrContext; 2.6 } 2.7 + 2.8 + @Override 2.9 + public String toString() { 2.10 + return "CheckContext: basicHandler"; 2.11 + } 2.12 }; 2.13 2.14 /** Check that a given type is assignable to a given proto-type.
3.1 --- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Wed May 07 10:59:12 2014 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Wed May 07 21:33:15 2014 -0700 3.3 @@ -110,6 +110,11 @@ 3.4 void complete() { 3.5 Assert.error("Empty deferred context!"); 3.6 } 3.7 + 3.8 + @Override 3.9 + public String toString() { 3.10 + return "Empty deferred context!"; 3.11 + } 3.12 }; 3.13 } 3.14
4.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Wed May 07 10:59:12 2014 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Wed May 07 21:33:15 2014 -0700 4.3 @@ -142,24 +142,24 @@ 4.4 * Main inference entry point - instantiate a generic method type 4.5 * using given argument types and (possibly) an expected target-type. 4.6 */ 4.7 - public Type instantiateMethod(Env<AttrContext> env, 4.8 - List<Type> tvars, 4.9 - MethodType mt, 4.10 - Attr.ResultInfo resultInfo, 4.11 - Symbol msym, 4.12 - List<Type> argtypes, 4.13 - boolean allowBoxing, 4.14 - boolean useVarargs, 4.15 - Resolve.MethodResolutionContext resolveContext, 4.16 - Warner warn) throws InferenceException { 4.17 + Type instantiateMethod( Env<AttrContext> env, 4.18 + List<Type> tvars, 4.19 + MethodType mt, 4.20 + Attr.ResultInfo resultInfo, 4.21 + MethodSymbol msym, 4.22 + List<Type> argtypes, 4.23 + boolean allowBoxing, 4.24 + boolean useVarargs, 4.25 + Resolve.MethodResolutionContext resolveContext, 4.26 + Warner warn) throws InferenceException { 4.27 //-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG 4.28 - final InferenceContext inferenceContext = new InferenceContext(tvars); 4.29 + final InferenceContext inferenceContext = new InferenceContext(tvars); //B0 4.30 inferenceException.clear(); 4.31 try { 4.32 DeferredAttr.DeferredAttrContext deferredAttrContext = 4.33 resolveContext.deferredAttrContext(msym, inferenceContext, resultInfo, warn); 4.34 4.35 - resolveContext.methodCheck.argumentsAcceptable(env, deferredAttrContext, 4.36 + resolveContext.methodCheck.argumentsAcceptable(env, deferredAttrContext, //B2 4.37 argtypes, mt.getParameterTypes(), warn); 4.38 4.39 if (allowGraphInference && 4.40 @@ -167,7 +167,8 @@ 4.41 !warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED)) { 4.42 //inject return constraints earlier 4.43 checkWithinBounds(inferenceContext, warn); //propagation 4.44 - Type newRestype = generateReturnConstraints(resultInfo, mt, inferenceContext); 4.45 + Type newRestype = generateReturnConstraints(env.tree, resultInfo, //B3 4.46 + mt, inferenceContext); 4.47 mt = (MethodType)types.createMethodTypeWithReturn(mt, newRestype); 4.48 //propagate outwards if needed 4.49 if (resultInfo.checkContext.inferenceContext().free(resultInfo.pt)) { 4.50 @@ -193,7 +194,7 @@ 4.51 inferenceContext.restvars().nonEmpty() && 4.52 resultInfo != null && 4.53 !warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED)) { 4.54 - generateReturnConstraints(resultInfo, mt, inferenceContext); 4.55 + generateReturnConstraints(env.tree, resultInfo, mt, inferenceContext); 4.56 inferenceContext.solveLegacy(false, warn, LegacyInferenceSteps.EQ_UPPER.steps); //maximizeInst 4.57 mt = (MethodType)inferenceContext.asInstType(mt); 4.58 } 4.59 @@ -210,6 +211,12 @@ 4.60 } else { 4.61 inferenceContext.notifyChange(inferenceContext.boundedVars()); 4.62 } 4.63 + if (resultInfo == null) { 4.64 + /* if the is no result info then we can clear the capture types 4.65 + * cache without affecting any result info check 4.66 + */ 4.67 + inferenceContext.captureTypeCache.clear(); 4.68 + } 4.69 } 4.70 } 4.71 4.72 @@ -218,7 +225,7 @@ 4.73 * call occurs in a context where a type T is expected, use the expected 4.74 * type to derive more constraints on the generic method inference variables. 4.75 */ 4.76 - Type generateReturnConstraints(Attr.ResultInfo resultInfo, 4.77 + Type generateReturnConstraints(JCTree tree, Attr.ResultInfo resultInfo, 4.78 MethodType mt, InferenceContext inferenceContext) { 4.79 InferenceContext rsInfoInfContext = resultInfo.checkContext.inferenceContext(); 4.80 Type from = mt.getReturnType(); 4.81 @@ -232,13 +239,29 @@ 4.82 } 4.83 } 4.84 } 4.85 - Type qtype1 = inferenceContext.asUndetVar(from); 4.86 - Type to = returnConstraintTarget(qtype1, resultInfo.pt); 4.87 + Type qtype = inferenceContext.asUndetVar(from); 4.88 + Type to = resultInfo.pt; 4.89 + 4.90 + if (qtype.hasTag(VOID)) { 4.91 + to = syms.voidType; 4.92 + } else if (to.hasTag(NONE)) { 4.93 + to = from.isPrimitive() ? from : syms.objectType; 4.94 + } else if (qtype.hasTag(UNDETVAR)) { 4.95 + if (resultInfo.pt.isReference()) { 4.96 + to = generateReturnConstraintsUndetVarToReference( 4.97 + tree, (UndetVar)qtype, to, resultInfo, inferenceContext); 4.98 + } else { 4.99 + if (to.isPrimitive()) { 4.100 + to = generateReturnConstraintsPrimitive(tree, (UndetVar)qtype, to, 4.101 + resultInfo, inferenceContext); 4.102 + } 4.103 + } 4.104 + } 4.105 Assert.check(allowGraphInference || !rsInfoInfContext.free(to), 4.106 "legacy inference engine cannot handle constraints on both sides of a subtyping assertion"); 4.107 //we need to skip capture? 4.108 Warner retWarn = new Warner(); 4.109 - if (!resultInfo.checkContext.compatible(qtype1, rsInfoInfContext.asUndetVar(to), retWarn) || 4.110 + if (!resultInfo.checkContext.compatible(qtype, rsInfoInfContext.asUndetVar(to), retWarn) || 4.111 //unchecked conversion is not allowed in source 7 mode 4.112 (!allowGraphInference && retWarn.hasLint(Lint.LintCategory.UNCHECKED))) { 4.113 throw inferenceException 4.114 @@ -248,30 +271,96 @@ 4.115 return from; 4.116 } 4.117 4.118 - Type returnConstraintTarget(Type from, Type to) { 4.119 - if (from.hasTag(VOID)) { 4.120 - return syms.voidType; 4.121 - } else if (to.hasTag(NONE)) { 4.122 - return from.isPrimitive() ? from : syms.objectType; 4.123 - } else if (from.hasTag(UNDETVAR) && to.isPrimitive()) { 4.124 - if (!allowGraphInference) { 4.125 - //if legacy, just return boxed type 4.126 - return types.boxedClass(to).type; 4.127 + private Type generateReturnConstraintsPrimitive(JCTree tree, UndetVar from, 4.128 + Type to, Attr.ResultInfo resultInfo, InferenceContext inferenceContext) { 4.129 + if (!allowGraphInference) { 4.130 + //if legacy, just return boxed type 4.131 + return types.boxedClass(to).type; 4.132 + } 4.133 + //if graph inference we need to skip conflicting boxed bounds... 4.134 + for (Type t : from.getBounds(InferenceBound.EQ, InferenceBound.UPPER, 4.135 + InferenceBound.LOWER)) { 4.136 + Type boundAsPrimitive = types.unboxedType(t); 4.137 + if (boundAsPrimitive == null || boundAsPrimitive.hasTag(NONE)) { 4.138 + continue; 4.139 } 4.140 - //if graph inference we need to skip conflicting boxed bounds... 4.141 - UndetVar uv = (UndetVar)from; 4.142 - for (Type t : uv.getBounds(InferenceBound.EQ, InferenceBound.LOWER)) { 4.143 - Type boundAsPrimitive = types.unboxedType(t); 4.144 - if (boundAsPrimitive == null) continue; 4.145 - if (types.isConvertible(boundAsPrimitive, to)) { 4.146 - //effectively skip return-type constraint generation (compatibility) 4.147 - return syms.objectType; 4.148 + return generateReferenceToTargetConstraint(tree, from, to, 4.149 + resultInfo, inferenceContext); 4.150 + } 4.151 + return types.boxedClass(to).type; 4.152 + } 4.153 + 4.154 + private Type generateReturnConstraintsUndetVarToReference(JCTree tree, 4.155 + UndetVar from, Type to, Attr.ResultInfo resultInfo, 4.156 + InferenceContext inferenceContext) { 4.157 + Type captureOfTo = types.capture(to); 4.158 + /* T is a reference type, but is not a wildcard-parameterized type, and either 4.159 + */ 4.160 + if (captureOfTo == to) { //not a wildcard parameterized type 4.161 + /* i) B2 contains a bound of one of the forms alpha = S or S <: alpha, 4.162 + * where S is a wildcard-parameterized type, or 4.163 + */ 4.164 + for (Type t : from.getBounds(InferenceBound.EQ, InferenceBound.LOWER)) { 4.165 + Type captureOfBound = types.capture(t); 4.166 + if (captureOfBound != t) { 4.167 + return generateReferenceToTargetConstraint(tree, from, to, 4.168 + resultInfo, inferenceContext); 4.169 } 4.170 } 4.171 - return types.boxedClass(to).type; 4.172 - } else { 4.173 - return to; 4.174 + 4.175 + /* ii) B2 contains two bounds of the forms S1 <: alpha and S2 <: alpha, 4.176 + * where S1 and S2 have supertypes that are two different 4.177 + * parameterizations of the same generic class or interface. 4.178 + */ 4.179 + for (Type aLowerBound : from.getBounds(InferenceBound.LOWER)) { 4.180 + for (Type anotherLowerBound : from.getBounds(InferenceBound.LOWER)) { 4.181 + if (aLowerBound != anotherLowerBound && 4.182 + commonSuperWithDiffParameterization(aLowerBound, anotherLowerBound)) { 4.183 + /* self comment check if any lower bound may be and undetVar, 4.184 + * in that case the result of this call may be a false positive. 4.185 + * Should this be restricted to non free types? 4.186 + */ 4.187 + return generateReferenceToTargetConstraint(tree, from, to, 4.188 + resultInfo, inferenceContext); 4.189 + } 4.190 + } 4.191 + } 4.192 } 4.193 + 4.194 + /* T is a parameterization of a generic class or interface, G, 4.195 + * and B2 contains a bound of one of the forms alpha = S or S <: alpha, 4.196 + * where there exists no type of the form G<...> that is a 4.197 + * supertype of S, but the raw type G is a supertype of S 4.198 + */ 4.199 + if (to.isParameterized()) { 4.200 + for (Type t : from.getBounds(InferenceBound.EQ, InferenceBound.LOWER)) { 4.201 + Type sup = types.asSuper(t, to.tsym); 4.202 + if (sup != null && sup.isRaw()) { 4.203 + return generateReferenceToTargetConstraint(tree, from, to, 4.204 + resultInfo, inferenceContext); 4.205 + } 4.206 + } 4.207 + } 4.208 + return to; 4.209 + } 4.210 + 4.211 + private boolean commonSuperWithDiffParameterization(Type t, Type s) { 4.212 + Pair<Type, Type> supers = getParameterizedSupers(t, s); 4.213 + return (supers != null && !types.isSameType(supers.fst, supers.snd)); 4.214 + } 4.215 + 4.216 + private Type generateReferenceToTargetConstraint(JCTree tree, UndetVar from, 4.217 + Type to, Attr.ResultInfo resultInfo, 4.218 + InferenceContext inferenceContext) { 4.219 + inferenceContext.solve(List.of(from.qtype), new Warner()); 4.220 + Type capturedType = resultInfo.checkContext.inferenceContext() 4.221 + .cachedCapture(tree, from.inst, false); 4.222 + if (types.isConvertible(capturedType, 4.223 + resultInfo.checkContext.inferenceContext().asUndetVar(to))) { 4.224 + //effectively skip additional return-type constraint generation (compatibility) 4.225 + return syms.objectType; 4.226 + } 4.227 + return to; 4.228 } 4.229 4.230 /** 4.231 @@ -2082,8 +2171,10 @@ 4.232 * Copy variable in this inference context to the given context 4.233 */ 4.234 void dupTo(final InferenceContext that) { 4.235 - that.inferencevars = that.inferencevars.appendList(inferencevars); 4.236 - that.undetvars = that.undetvars.appendList(undetvars); 4.237 + that.inferencevars = that.inferencevars.appendList( 4.238 + inferencevars.diff(that.inferencevars)); 4.239 + that.undetvars = that.undetvars.appendList( 4.240 + undetvars.diff(that.undetvars)); 4.241 //set up listeners to notify original inference contexts as 4.242 //propagated vars are inferred in new context 4.243 for (Type t : inferencevars) { 4.244 @@ -2202,6 +2293,30 @@ 4.245 return "Inference vars: " + inferencevars + '\n' + 4.246 "Undet vars: " + undetvars; 4.247 } 4.248 + 4.249 + /* Method Types.capture() generates a new type every time it's applied 4.250 + * to a wildcard parameterized type. This is intended functionality but 4.251 + * there are some cases when what you need is not to generate a new 4.252 + * captured type but to check that a previously generated captured type 4.253 + * is correct. There are cases when caching a captured type for later 4.254 + * reuse is sound. In general two captures from the same AST are equal. 4.255 + * This is why the tree is used as the key of the map below. This map 4.256 + * stores a Type per AST. 4.257 + */ 4.258 + Map<JCTree, Type> captureTypeCache = new HashMap<>(); 4.259 + 4.260 + Type cachedCapture(JCTree tree, Type t, boolean readOnly) { 4.261 + Type captured = captureTypeCache.get(tree); 4.262 + if (captured != null) { 4.263 + return captured; 4.264 + } 4.265 + 4.266 + Type result = types.capture(t); 4.267 + if (result != t && !readOnly) { // then t is a wildcard parameterized type 4.268 + captureTypeCache.put(tree, result); 4.269 + } 4.270 + return result; 4.271 + } 4.272 } 4.273 4.274 final InferenceContext emptyContext = new InferenceContext(List.<Type>nil());
5.1 --- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Wed May 07 10:59:12 2014 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Wed May 07 21:33:15 2014 -0700 5.3 @@ -36,6 +36,7 @@ 5.4 import com.sun.tools.javac.code.Symbol.ClassSymbol; 5.5 import com.sun.tools.javac.code.Symbol.DynamicMethodSymbol; 5.6 import com.sun.tools.javac.code.Symbol.MethodSymbol; 5.7 +import com.sun.tools.javac.code.Symbol.TypeSymbol; 5.8 import com.sun.tools.javac.code.Symbol.VarSymbol; 5.9 import com.sun.tools.javac.code.Symtab; 5.10 import com.sun.tools.javac.code.Type; 5.11 @@ -50,8 +51,10 @@ 5.12 5.13 import java.util.EnumMap; 5.14 import java.util.HashMap; 5.15 +import java.util.HashSet; 5.16 import java.util.LinkedHashMap; 5.17 import java.util.Map; 5.18 +import java.util.Set; 5.19 5.20 import static com.sun.tools.javac.comp.LambdaToMethod.LambdaSymbolKind.*; 5.21 import static com.sun.tools.javac.code.Flags.*; 5.22 @@ -438,13 +441,9 @@ 5.23 public void visitVarDef(JCVariableDecl tree) { 5.24 LambdaTranslationContext lambdaContext = (LambdaTranslationContext)context; 5.25 if (context != null && lambdaContext.getSymbolMap(LOCAL_VAR).containsKey(tree.sym)) { 5.26 - JCExpression init = translate(tree.init); 5.27 - int prevPos = make.pos; 5.28 - try { 5.29 - result = make.at(tree).VarDef((VarSymbol)lambdaContext.getSymbolMap(LOCAL_VAR).get(tree.sym), init); 5.30 - } finally { 5.31 - make.at(prevPos); 5.32 - } 5.33 + tree.init = translate(tree.init); 5.34 + tree.sym = (VarSymbol) lambdaContext.getSymbolMap(LOCAL_VAR).get(tree.sym); 5.35 + result = tree; 5.36 } else if (context != null && lambdaContext.getSymbolMap(TYPE_VAR).containsKey(tree.sym)) { 5.37 JCExpression init = translate(tree.init); 5.38 VarSymbol xsym = (VarSymbol)lambdaContext.getSymbolMap(TYPE_VAR).get(tree.sym); 5.39 @@ -1286,7 +1285,10 @@ 5.40 5.41 @Override 5.42 public void visitNewClass(JCNewClass tree) { 5.43 - if (lambdaNewClassFilter(context(), tree)) { 5.44 + TypeSymbol def = tree.type.tsym; 5.45 + boolean inReferencedClass = currentlyInClass(def); 5.46 + boolean isLocal = def.isLocal(); 5.47 + if ((inReferencedClass && isLocal || lambdaNewClassFilter(context(), tree))) { 5.48 TranslationContext<?> localContext = context(); 5.49 while (localContext != null) { 5.50 if (localContext.tree.getTag() == LAMBDA) { 5.51 @@ -1296,16 +1298,16 @@ 5.52 localContext = localContext.prev; 5.53 } 5.54 } 5.55 - if (context() != null && tree.type.tsym.owner.kind == MTH) { 5.56 + if (context() != null && !inReferencedClass && isLocal) { 5.57 LambdaTranslationContext lambdaContext = (LambdaTranslationContext)context(); 5.58 - captureLocalClassDefs(tree.type.tsym, lambdaContext); 5.59 + captureLocalClassDefs(def, lambdaContext); 5.60 } 5.61 super.visitNewClass(tree); 5.62 } 5.63 //where 5.64 void captureLocalClassDefs(Symbol csym, final LambdaTranslationContext lambdaContext) { 5.65 JCClassDecl localCDef = localClassDefs.get(csym); 5.66 - if (localCDef != null && localCDef.pos < lambdaContext.tree.pos) { 5.67 + if (localCDef != null && lambdaContext.freeVarProcessedLocalClasses.add(csym)) { 5.68 BasicFreeVarCollector fvc = lower.new BasicFreeVarCollector() { 5.69 @Override 5.70 void addFreeVars(ClassSymbol c) { 5.71 @@ -1331,6 +1333,18 @@ 5.72 fvc.scan(localCDef); 5.73 } 5.74 } 5.75 + //where 5.76 + boolean currentlyInClass(Symbol csym) { 5.77 + for (Frame frame : frameStack) { 5.78 + if (frame.tree.hasTag(JCTree.Tag.CLASSDEF)) { 5.79 + JCClassDecl cdef = (JCClassDecl) frame.tree; 5.80 + if (cdef.sym == csym) { 5.81 + return true; 5.82 + } 5.83 + } 5.84 + } 5.85 + return false; 5.86 + } 5.87 5.88 /** 5.89 * Method references to local class constructors, may, if the local 5.90 @@ -1756,6 +1770,11 @@ 5.91 5.92 List<JCVariableDecl> syntheticParams; 5.93 5.94 + /** 5.95 + * to prevent recursion, track local classes processed 5.96 + */ 5.97 + final Set<Symbol> freeVarProcessedLocalClasses; 5.98 + 5.99 LambdaTranslationContext(JCLambda tree) { 5.100 super(tree); 5.101 Frame frame = frameStack.head; 5.102 @@ -1785,6 +1804,8 @@ 5.103 translatedSymbols.put(CAPTURED_VAR, new LinkedHashMap<Symbol, Symbol>()); 5.104 translatedSymbols.put(CAPTURED_THIS, new LinkedHashMap<Symbol, Symbol>()); 5.105 translatedSymbols.put(TYPE_VAR, new LinkedHashMap<Symbol, Symbol>()); 5.106 + 5.107 + freeVarProcessedLocalClasses = new HashSet<>(); 5.108 } 5.109 5.110 /** 5.111 @@ -1895,7 +1916,7 @@ 5.112 }; 5.113 break; 5.114 case LOCAL_VAR: 5.115 - ret = new VarSymbol(sym.flags() & FINAL, name, types.erasure(sym.type), translatedSym); 5.116 + ret = new VarSymbol(sym.flags() & FINAL, name, sym.type, translatedSym); 5.117 ((VarSymbol) ret).pos = ((VarSymbol) sym).pos; 5.118 break; 5.119 case PARAM:
6.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed May 07 10:59:12 2014 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed May 07 21:33:15 2014 -0700 6.3 @@ -565,7 +565,7 @@ 6.4 tvars, 6.5 (MethodType)mt, 6.6 resultInfo, 6.7 - m, 6.8 + (MethodSymbol)m, 6.9 argtypes, 6.10 allowBoxing, 6.11 useVarargs, 6.12 @@ -773,6 +773,7 @@ 6.13 public MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict) { 6.14 return nilMethodCheck; 6.15 } 6.16 + 6.17 } 6.18 6.19 /** 6.20 @@ -784,6 +785,11 @@ 6.21 void checkArg(DiagnosticPosition pos, boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn) { 6.22 //do nothing - actual always compatible to formals 6.23 } 6.24 + 6.25 + @Override 6.26 + public String toString() { 6.27 + return "arityMethodCheck"; 6.28 + } 6.29 }; 6.30 6.31 List<Type> dummyArgs(int length) { 6.32 @@ -869,6 +875,11 @@ 6.33 public MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict) { 6.34 return new MostSpecificCheck(strict, actuals); 6.35 } 6.36 + 6.37 + @Override 6.38 + public String toString() { 6.39 + return "resolveMethodCheck"; 6.40 + } 6.41 }; 6.42 6.43 /** 6.44 @@ -900,7 +911,9 @@ 6.45 @Override 6.46 public boolean compatible(Type found, Type req, Warner warn) { 6.47 found = pendingInferenceContext.asUndetVar(found); 6.48 - req = infer.returnConstraintTarget(found, req); 6.49 + if (found.hasTag(UNDETVAR) && req.isPrimitive()) { 6.50 + req = types.boxedClass(req).type; 6.51 + } 6.52 return super.compatible(found, req, warn); 6.53 } 6.54 6.55 @@ -955,6 +968,12 @@ 6.56 public DeferredAttrContext deferredAttrContext() { 6.57 return deferredAttrContext; 6.58 } 6.59 + 6.60 + @Override 6.61 + public String toString() { 6.62 + return "MethodReferenceCheck"; 6.63 + } 6.64 + 6.65 } 6.66 6.67 /** 6.68 @@ -973,7 +992,12 @@ 6.69 DeferredType dt = (DeferredType)found; 6.70 return dt.check(this); 6.71 } else { 6.72 - return super.check(pos, chk.checkNonVoid(pos, types.capture(U(found.baseType())))); 6.73 + Type uResult = U(found.baseType()); 6.74 + Type capturedType = pos == null || pos.getTree() == null ? 6.75 + types.capture(uResult) : 6.76 + checkContext.inferenceContext() 6.77 + .cachedCapture(pos.getTree(), uResult, true); 6.78 + return super.check(pos, chk.checkNonVoid(pos, capturedType)); 6.79 } 6.80 } 6.81
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/tools/javac/inference/EagerReturnTypeResolution/EagerReturnTypeResolutionTesta.java Wed May 07 21:33:15 2014 -0700 7.3 @@ -0,0 +1,78 @@ 7.4 +/* 7.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.7 + * 7.8 + * This code is free software; you can redistribute it and/or modify it 7.9 + * under the terms of the GNU General Public License version 2 only, as 7.10 + * published by the Free Software Foundation. Oracle designates this 7.11 + * particular file as subject to the "Classpath" exception as provided 7.12 + * by Oracle in the LICENSE file that accompanied this code. 7.13 + * 7.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 7.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.17 + * version 2 for more details (a copy is included in the LICENSE file that 7.18 + * accompanied this code). 7.19 + * 7.20 + * You should have received a copy of the GNU General Public License version 7.21 + * 2 along with this work; if not, write to the Free Software Foundation, 7.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.23 + * 7.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 7.25 + * or visit www.oracle.com if you need additional information or have any 7.26 + * questions. 7.27 + */ 7.28 + 7.29 +/* 7.30 + * @test 7.31 + * @bug 8030741 7.32 + * @summary Inference: implement eager resolution of return types, consistent with JDK-8028800 7.33 + * @compile EagerReturnTypeResolutionTesta.java 7.34 + */ 7.35 + 7.36 +public class EagerReturnTypeResolutionTesta { 7.37 + 7.38 + abstract class Test1<T>{ 7.39 + abstract <S> S foo(S x, S y); 7.40 + <S extends Number & Comparable<? extends Number>> void baz(Test1<S> a){} 7.41 + 7.42 + void bar(Test1<Long> x, Test1<Integer> y){ 7.43 + baz(foo(x, y)); 7.44 + } 7.45 + } 7.46 + 7.47 + abstract class Test2<T>{ 7.48 + abstract <S> S foo(S x, S y); 7.49 + abstract <S1> void baz(Test2<S1> a); 7.50 + 7.51 + void bar(Test2<Integer> y, Test2<Long> x){ 7.52 + baz(foo(x, y)); 7.53 + } 7.54 + } 7.55 + 7.56 + abstract class Test3<T>{ 7.57 + abstract <S> S foo(S x, S y); 7.58 + <T extends Number & Comparable<?>, 7.59 + S extends Number & Comparable<? extends T>> void baz(Test3<S> a){} 7.60 + 7.61 + void bar(Test3<Long> x, Test3<Integer> y){ 7.62 + baz(foo(x, y)); 7.63 + } 7.64 + } 7.65 + 7.66 + abstract class Test4 { 7.67 + abstract class A0<T> {} 7.68 + 7.69 + abstract class A1<T> extends A0<T> {} 7.70 + 7.71 + abstract class A2<T> extends A0<T> {} 7.72 + 7.73 + abstract <S> S foo(S x, S y); 7.74 + abstract <S1> void baz(A0<S1> a); 7.75 + 7.76 + void bar(A2<Integer> y, A1<Long> x){ 7.77 + baz(foo(x, y)); 7.78 + } 7.79 + } 7.80 + 7.81 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/test/tools/javac/inference/EagerReturnTypeResolution/EagerReturnTypeResolutionTestb.java Wed May 07 21:33:15 2014 -0700 8.3 @@ -0,0 +1,182 @@ 8.4 +/* 8.5 + * @test /nodynamiccopyright/ 8.6 + * @bug 8030741 8.7 + * @summary Inference: implement eager resolution of return types, consistent with JDK-8028800 8.8 + * @compile/fail/ref=EagerReturnTypeResolutionTestb.out -XDrawDiagnostics EagerReturnTypeResolutionTestb.java 8.9 + * @author Dan Smith 8.10 + */ 8.11 + 8.12 +import java.util.List; 8.13 + 8.14 +public class EagerReturnTypeResolutionTestb { 8.15 + interface I<S> {} 8.16 + interface J<S> extends I<S> {} 8.17 + interface K extends I<String> {} 8.18 + interface L<S> extends I {} 8.19 + 8.20 + <T> T lower(List<? extends T> l) { return null; } 8.21 + <T> T lower2(List<? extends T> l1, List<? extends T> l2) { return null; } 8.22 + 8.23 + <T> T upper(List<? super T> l) { return null; } 8.24 + <T> T upper2(List<? super T> l1, List<? super T> l2) { return null; } 8.25 + 8.26 + <T> T eq(List<T> l) { return null; } 8.27 + <T> T eq2(List<T> l1, List<T> l2) { return null; } 8.28 + 8.29 + <X> void takeI(I<X> i) {} 8.30 + void takeIString(I<String> i) {} 8.31 + I<String> iStringField; 8.32 + 8.33 + void takeLong(long arg) {} 8.34 + long longField; 8.35 + 8.36 + void testSimpleCaptureOK(List<I<?>> i1) { 8.37 + takeI(lower(i1)); // ok* 8.38 + takeI(eq(i1)); // ok* 8.39 + takeI(upper(i1)); // ok, no capture 8.40 + takeIString(upper(i1)); // ok 8.41 + iStringField = upper(i1); // ok 8.42 + } 8.43 + 8.44 + void testSimpleCaptureKO(List<I<?>> i1) { 8.45 + takeIString(lower(i1)); // ERROR 8.46 + takeIString(eq(i1)); // ERROR 8.47 + iStringField = lower(i1); // ERROR 8.48 + iStringField = eq(i1); // ERROR 8.49 + } 8.50 + 8.51 + void testMultiCaptureOK(List<I<String>> i1, List<I<Integer>> i2, List<I<?>> i3, 8.52 + List<J<String>> j1, List<J<Integer>> j2, List<K> k1) { 8.53 + /* Lines marked with JDK-8029002 should be uncommented once this bug is 8.54 + * fixed 8.55 + */ 8.56 + takeI(lower2(i1, i2)); // ok* 8.57 + takeI(lower2(i1, i3)); // ok* 8.58 + takeI(upper2(i1, i3)); // ok, no capture* JDK-8029002 8.59 + 8.60 + takeIString(upper2(i1, i3)); // ok, no capture 8.61 + iStringField = upper2(i1, i3); // ok, no capture 8.62 + 8.63 + takeI(lower2(j1, j2)); // ok* 8.64 + takeI(lower2(j1, k1)); // ok, no capture 8.65 + takeI(upper2(j1, k1)); // ok, no capture* JDK-8029002 8.66 + 8.67 + takeIString(lower2(j1, k1)); // ok, no capture 8.68 + takeIString(upper2(j1, k1)); // ok, no capture 8.69 + 8.70 + iStringField = lower2(j1, k1); // ok, no capture 8.71 + iStringField = upper2(j1, k1); // ok, no capture 8.72 + takeI(lower2(j2, k1)); // ok* 8.73 + } 8.74 + 8.75 + void testMultiCaptureKO(List<I<String>> i1, List<I<Integer>> i2, List<I<?>> i3, 8.76 + List<J<String>> j1, List<J<Integer>> j2, List<K> k1) { 8.77 + takeI(eq2(i1, i2)); // ERROR, bad bounds 8.78 + takeI(upper2(i1, i2)); // ERROR, bad bounds 8.79 + 8.80 + takeIString(lower2(i1, i2)); // ERROR 8.81 + takeIString(eq2(i1, i2)); // ERROR, bad bounds 8.82 + takeIString(upper2(i1, i2)); // ERROR, bad bounds 8.83 + 8.84 + iStringField = lower2(i1, i2); // ERROR 8.85 + iStringField = eq2(i1, i2); // ERROR, bad bounds 8.86 + iStringField = upper2(i1, i2); // ERROR, bad bounds 8.87 + 8.88 + takeI(eq2(i1, i3)); // ERROR, bad bounds 8.89 + takeIString(lower2(i1, i3)); // ERROR 8.90 + takeIString(eq2(i1, i3)); // ERROR, bad bounds 8.91 + 8.92 + iStringField = lower2(i1, i3); // ERROR 8.93 + iStringField = eq2(i1, i3); // ERROR, bad bounds 8.94 + takeI(eq2(j1, j2)); // ERROR, bad bounds 8.95 + takeI(upper2(j1, j2)); // ERROR, bad bounds 8.96 + 8.97 + takeIString(lower2(j1, j2)); // ERROR 8.98 + takeIString(eq2(j1, j2)); // ERROR, bad bounds 8.99 + takeIString(upper2(j1, j2)); // ERROR, bad bounds 8.100 + 8.101 + iStringField = lower2(j1, j2); // ERROR 8.102 + iStringField = eq2(j1, j2); // ERROR, bad bounds 8.103 + iStringField = upper2(j1, j2); // ERROR, bad bounds 8.104 + 8.105 + takeI(eq2(j1, k1)); // ERROR, bad bounds 8.106 + takeIString(eq2(j1, k1)); // ERROR, bad bounds 8.107 + iStringField = eq2(j1, k1); // ERROR, bad bounds 8.108 + takeI(eq2(j2, k1)); // ERROR, bad bounds 8.109 + takeI(upper2(j2, k1)); // ERROR, bad bounds; actual: no error, see JDK-8037474 8.110 + 8.111 + takeIString(lower2(j2, k1)); // ERROR 8.112 + takeIString(eq2(j2, k1)); // ERROR, bad bounds 8.113 + takeIString(upper2(j2, k1)); // ERROR, bad bounds 8.114 + 8.115 + iStringField = lower2(j2, k1); // ERROR 8.116 + iStringField = eq2(j2, k1); // ERROR, bad bounds 8.117 + iStringField = upper2(j2, k1); // ERROR, bad bounds 8.118 + } 8.119 + 8.120 + void testRawOK(List<I> i1, List<J> j1, List<L<String>> l1) { 8.121 + takeI(lower(i1)); // ok, unchecked 8.122 + takeI(eq(i1)); // ok, unchecked 8.123 + takeI(upper(i1)); // ok, no capture, not unchecked 8.124 + 8.125 + takeIString(lower(i1)); // ok, unchecked 8.126 + takeIString(eq(i1)); // ok, unchecked 8.127 + takeIString(upper(i1)); // ok, no capture, not unchecked 8.128 + 8.129 + iStringField = lower(i1); // ok, unchecked 8.130 + iStringField = eq(i1); // ok, unchecked 8.131 + iStringField = upper(i1); // ok, no capture, not unchecked 8.132 + 8.133 + takeI(lower(j1)); // ok, unchecked 8.134 + takeI(eq(j1)); // ok, unchecked 8.135 + takeI(upper(j1)); // bad bounds? -- spec is unclear 8.136 + 8.137 + takeIString(lower(j1)); // ok, unchecked 8.138 + takeIString(eq(j1)); // ok, unchecked 8.139 + takeIString(upper(j1)); // bad bounds? -- spec is unclear 8.140 + 8.141 + iStringField = lower(j1); // ok, unchecked 8.142 + iStringField = eq(j1); // ok, unchecked 8.143 + iStringField = upper(j1); // bad bounds? -- spec is unclear 8.144 + 8.145 + takeI(lower(l1)); // ok, unchecked 8.146 + takeI(eq(l1)); // ok, unchecked 8.147 + takeI(upper(l1)); // bad bounds? -- spec is unclear 8.148 + 8.149 + takeIString(lower(l1)); // ok, unchecked 8.150 + takeIString(eq(l1)); // ok, unchecked 8.151 + takeIString(upper(l1)); // bad bounds? -- spec is unclear 8.152 + 8.153 + iStringField = lower(l1); // ok, unchecked 8.154 + iStringField = eq(l1); // ok, unchecked 8.155 + iStringField = upper(l1); // bad bounds? -- spec is unclear 8.156 + } 8.157 + 8.158 + void testPrimOK(List<Integer> i1, List<Long> l1, List<Double> d1) { 8.159 + takeLong(lower(i1)); // ok 8.160 + takeLong(eq(i1)); // ok 8.161 + takeLong(upper(i1)); // ok* 8.162 + 8.163 + longField = lower(i1); // ok 8.164 + longField = eq(i1); // ok 8.165 + longField = upper(i1); // ok* 8.166 + 8.167 + takeLong(lower(l1)); // ok 8.168 + takeLong(eq(l1)); // ok 8.169 + takeLong(upper(l1)); // ok 8.170 + 8.171 + longField = lower(l1); // ok 8.172 + longField = eq(l1); // ok 8.173 + longField = upper(l1); // ok 8.174 + } 8.175 + 8.176 + void testPrimKO(List<Integer> i1, List<Long> l1, List<Double> d1) { 8.177 + takeLong(lower(d1)); // ERROR 8.178 + takeLong(eq(d1)); // ERROR 8.179 + takeLong(upper(d1)); // ERROR 8.180 + 8.181 + longField = lower(d1); // ERROR 8.182 + longField = eq(d1); // ERROR 8.183 + longField = upper(d1); // ERROR 8.184 + } 8.185 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/test/tools/javac/inference/EagerReturnTypeResolution/EagerReturnTypeResolutionTestb.out Wed May 07 21:33:15 2014 -0700 9.3 @@ -0,0 +1,45 @@ 9.4 +EagerReturnTypeResolutionTestb.java:42:9: compiler.err.cant.apply.symbol: kindname.method, takeIString, EagerReturnTypeResolutionTestb.I<java.lang.String>, EagerReturnTypeResolutionTestb.I<compiler.misc.type.captureof: 1, ?>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object)) 9.5 +EagerReturnTypeResolutionTestb.java:43:9: compiler.err.cant.apply.symbol: kindname.method, takeIString, EagerReturnTypeResolutionTestb.I<java.lang.String>, EagerReturnTypeResolutionTestb.I<compiler.misc.type.captureof: 1, ?>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object)) 9.6 +EagerReturnTypeResolutionTestb.java:44:29: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) 9.7 +EagerReturnTypeResolutionTestb.java:45:26: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) 9.8 +EagerReturnTypeResolutionTestb.java:74:15: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.I<java.lang.Integer>, EagerReturnTypeResolutionTestb.I<java.lang.Integer>,EagerReturnTypeResolutionTestb.I<java.lang.String>) 9.9 +EagerReturnTypeResolutionTestb.java:75:15: compiler.err.cant.apply.symbol: kindname.method, upper2, java.util.List<? super T>,java.util.List<? super T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<java.lang.Integer>, EagerReturnTypeResolutionTestb.I<java.lang.Integer>,EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) 9.10 +EagerReturnTypeResolutionTestb.java:77:9: compiler.err.cant.apply.symbol: kindname.method, takeIString, EagerReturnTypeResolutionTestb.I<java.lang.String>, EagerReturnTypeResolutionTestb.I<compiler.misc.type.captureof: 1, ? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object)) 9.11 +EagerReturnTypeResolutionTestb.java:78:21: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.I<java.lang.Integer>, EagerReturnTypeResolutionTestb.I<java.lang.Integer>,EagerReturnTypeResolutionTestb.I<java.lang.String>) 9.12 +EagerReturnTypeResolutionTestb.java:79:21: compiler.err.cant.apply.symbol: kindname.method, upper2, java.util.List<? super T>,java.util.List<? super T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<java.lang.Integer>, EagerReturnTypeResolutionTestb.I<java.lang.Integer>,EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) 9.13 +EagerReturnTypeResolutionTestb.java:81:30: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) 9.14 +EagerReturnTypeResolutionTestb.java:82:24: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.I<java.lang.Integer>, EagerReturnTypeResolutionTestb.I<java.lang.Integer>,EagerReturnTypeResolutionTestb.I<java.lang.String>) 9.15 +EagerReturnTypeResolutionTestb.java:83:24: compiler.err.cant.apply.symbol: kindname.method, upper2, java.util.List<? super T>,java.util.List<? super T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<java.lang.Integer>, EagerReturnTypeResolutionTestb.I<java.lang.Integer>,EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) 9.16 +EagerReturnTypeResolutionTestb.java:85:15: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<?>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<?>,EagerReturnTypeResolutionTestb.I<java.lang.String>) 9.17 +EagerReturnTypeResolutionTestb.java:86:9: compiler.err.cant.apply.symbol: kindname.method, takeIString, EagerReturnTypeResolutionTestb.I<java.lang.String>, EagerReturnTypeResolutionTestb.I<compiler.misc.type.captureof: 1, ?>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object)) 9.18 +EagerReturnTypeResolutionTestb.java:87:21: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<?>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<?>,EagerReturnTypeResolutionTestb.I<java.lang.String>) 9.19 +EagerReturnTypeResolutionTestb.java:89:30: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) 9.20 +EagerReturnTypeResolutionTestb.java:90:24: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<?>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<?>,EagerReturnTypeResolutionTestb.I<java.lang.String>) 9.21 +EagerReturnTypeResolutionTestb.java:91:15: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.J<java.lang.Integer>, EagerReturnTypeResolutionTestb.J<java.lang.Integer>,EagerReturnTypeResolutionTestb.J<java.lang.String>) 9.22 +EagerReturnTypeResolutionTestb.java:92:15: compiler.err.cant.apply.symbol: kindname.method, upper2, java.util.List<? super T>,java.util.List<? super T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.J<java.lang.Integer>, EagerReturnTypeResolutionTestb.J<java.lang.Integer>,EagerReturnTypeResolutionTestb.J<java.lang.String>,java.lang.Object) 9.23 +EagerReturnTypeResolutionTestb.java:94:9: compiler.err.cant.apply.symbol: kindname.method, takeIString, EagerReturnTypeResolutionTestb.I<java.lang.String>, EagerReturnTypeResolutionTestb.J<compiler.misc.type.captureof: 1, ? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.J<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object)) 9.24 +EagerReturnTypeResolutionTestb.java:95:21: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.J<java.lang.Integer>, EagerReturnTypeResolutionTestb.J<java.lang.Integer>,EagerReturnTypeResolutionTestb.J<java.lang.String>) 9.25 +EagerReturnTypeResolutionTestb.java:96:21: compiler.err.cant.apply.symbol: kindname.method, upper2, java.util.List<? super T>,java.util.List<? super T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.J<java.lang.Integer>, EagerReturnTypeResolutionTestb.J<java.lang.Integer>,EagerReturnTypeResolutionTestb.J<java.lang.String>,java.lang.Object) 9.26 +EagerReturnTypeResolutionTestb.java:98:30: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.J<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) 9.27 +EagerReturnTypeResolutionTestb.java:99:24: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.J<java.lang.Integer>, EagerReturnTypeResolutionTestb.J<java.lang.Integer>,EagerReturnTypeResolutionTestb.J<java.lang.String>) 9.28 +EagerReturnTypeResolutionTestb.java:100:24: compiler.err.cant.apply.symbol: kindname.method, upper2, java.util.List<? super T>,java.util.List<? super T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.J<java.lang.Integer>, EagerReturnTypeResolutionTestb.J<java.lang.Integer>,EagerReturnTypeResolutionTestb.J<java.lang.String>,java.lang.Object) 9.29 +EagerReturnTypeResolutionTestb.java:102:15: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.K>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.K, EagerReturnTypeResolutionTestb.K,EagerReturnTypeResolutionTestb.J<java.lang.String>) 9.30 +EagerReturnTypeResolutionTestb.java:103:21: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.K>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.K, EagerReturnTypeResolutionTestb.K,EagerReturnTypeResolutionTestb.J<java.lang.String>) 9.31 +EagerReturnTypeResolutionTestb.java:104:24: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.K>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.K, EagerReturnTypeResolutionTestb.K,EagerReturnTypeResolutionTestb.J<java.lang.String>) 9.32 +EagerReturnTypeResolutionTestb.java:105:15: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>,java.util.List<EagerReturnTypeResolutionTestb.K>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.K, EagerReturnTypeResolutionTestb.K,EagerReturnTypeResolutionTestb.J<java.lang.Integer>) 9.33 +EagerReturnTypeResolutionTestb.java:106:9: compiler.err.cant.apply.symbol: kindname.method, takeI, EagerReturnTypeResolutionTestb.I<X>, java.lang.Object&EagerReturnTypeResolutionTestb.J<java.lang.Integer>&EagerReturnTypeResolutionTestb.K, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: java.lang.Integer, java.lang.Integer,java.lang.String) 9.34 +EagerReturnTypeResolutionTestb.java:108:9: compiler.err.cant.apply.symbol: kindname.method, takeIString, EagerReturnTypeResolutionTestb.I<java.lang.String>, EagerReturnTypeResolutionTestb.I<compiler.misc.type.captureof: 1, ? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object)) 9.35 +EagerReturnTypeResolutionTestb.java:109:21: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>,java.util.List<EagerReturnTypeResolutionTestb.K>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.K, EagerReturnTypeResolutionTestb.K,EagerReturnTypeResolutionTestb.J<java.lang.Integer>) 9.36 +EagerReturnTypeResolutionTestb.java:110:9: compiler.err.cant.apply.symbol: kindname.method, takeIString, EagerReturnTypeResolutionTestb.I<java.lang.String>, java.lang.Object&EagerReturnTypeResolutionTestb.J<java.lang.Integer>&EagerReturnTypeResolutionTestb.K, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Object&EagerReturnTypeResolutionTestb.J<java.lang.Integer>&EagerReturnTypeResolutionTestb.K, EagerReturnTypeResolutionTestb.I<java.lang.String>,EagerReturnTypeResolutionTestb.K,EagerReturnTypeResolutionTestb.J<java.lang.Integer>,java.lang.Object)) 9.37 +EagerReturnTypeResolutionTestb.java:112:30: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) 9.38 +EagerReturnTypeResolutionTestb.java:113:24: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>,java.util.List<EagerReturnTypeResolutionTestb.K>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.K, EagerReturnTypeResolutionTestb.K,EagerReturnTypeResolutionTestb.J<java.lang.Integer>) 9.39 +EagerReturnTypeResolutionTestb.java:114:30: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Object&EagerReturnTypeResolutionTestb.J<java.lang.Integer>&EagerReturnTypeResolutionTestb.K, EagerReturnTypeResolutionTestb.I<java.lang.String>,EagerReturnTypeResolutionTestb.K,EagerReturnTypeResolutionTestb.J<java.lang.Integer>,java.lang.Object) 9.40 +EagerReturnTypeResolutionTestb.java:174:9: compiler.err.cant.apply.symbol: kindname.method, takeLong, long, java.lang.Double, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.infer.no.conforming.instance.exists: , T, long)) 9.41 +EagerReturnTypeResolutionTestb.java:175:9: compiler.err.cant.apply.symbol: kindname.method, takeLong, long, java.lang.Double, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.infer.no.conforming.instance.exists: , T, long)) 9.42 +EagerReturnTypeResolutionTestb.java:176:9: compiler.err.cant.apply.symbol: kindname.method, takeLong, long, java.lang.Double, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.infer.no.conforming.instance.exists: , T, long)) 9.43 +EagerReturnTypeResolutionTestb.java:178:26: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.instance.exists: , T, long) 9.44 +EagerReturnTypeResolutionTestb.java:179:23: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.instance.exists: , T, long) 9.45 +EagerReturnTypeResolutionTestb.java:180:26: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.instance.exists: , T, long) 9.46 +- compiler.note.unchecked.filename: EagerReturnTypeResolutionTestb.java 9.47 +- compiler.note.unchecked.recompile 9.48 +42 errors
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/test/tools/javac/inference/EagerReturnTypeResolution/PrimitiveTypeBoxingTest.java Wed May 07 21:33:15 2014 -0700 10.3 @@ -0,0 +1,25 @@ 10.4 +/* 10.5 + * @test /nodynamiccopyright/ 10.6 + * @bug 8030741 10.7 + * @summary Inference: implement eager resolution of return types, consistent with JDK-8028800 10.8 + * @compile/fail/ref=PrimitiveTypeBoxingTest.out -XDrawDiagnostics PrimitiveTypeBoxingTest.java 10.9 + */ 10.10 + 10.11 +public class PrimitiveTypeBoxingTest { 10.12 + 10.13 + static void foo(long arg) {} 10.14 + static void bar(int arg) {} 10.15 + 10.16 + interface F<X> { void get(X arg); } 10.17 + 10.18 + <Z> void m1(F<Z> f, Z arg) {} 10.19 + <Z> void m2(Z arg, F<Z> f) {} 10.20 + 10.21 + void test() { 10.22 + m1(PrimitiveTypeBoxingTest::foo, 23); // expected: error 10.23 + m2(23, PrimitiveTypeBoxingTest::foo); // expected: error 10.24 + 10.25 + m1(PrimitiveTypeBoxingTest::bar, 23); // expected: success 10.26 + m2(23, PrimitiveTypeBoxingTest::bar); // expected: success 10.27 + } 10.28 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/test/tools/javac/inference/EagerReturnTypeResolution/PrimitiveTypeBoxingTest.out Wed May 07 21:33:15 2014 -0700 11.3 @@ -0,0 +1,3 @@ 11.4 +PrimitiveTypeBoxingTest.java:19:9: compiler.err.cant.apply.symbol: kindname.method, m1, PrimitiveTypeBoxingTest.F<Z>,Z, @490,int, kindname.class, PrimitiveTypeBoxingTest, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, java.lang.Long,java.lang.Object) 11.5 +PrimitiveTypeBoxingTest.java:20:9: compiler.err.cant.apply.symbol: kindname.method, m2, Z,PrimitiveTypeBoxingTest.F<Z>, int,@559, kindname.class, PrimitiveTypeBoxingTest, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, java.lang.Long,java.lang.Object) 11.6 +2 errors
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/tools/javac/lambda/LambdaLocalTest.java Wed May 07 21:33:15 2014 -0700 12.3 @@ -0,0 +1,55 @@ 12.4 +/* 12.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.7 + * 12.8 + * This code is free software; you can redistribute it and/or modify it 12.9 + * under the terms of the GNU General Public License version 2 only, as 12.10 + * published by the Free Software Foundation. 12.11 + * 12.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 12.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12.15 + * version 2 for more details (a copy is included in the LICENSE file that 12.16 + * accompanied this code). 12.17 + * 12.18 + * You should have received a copy of the GNU General Public License version 12.19 + * 2 along with this work; if not, write to the Free Software Foundation, 12.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 12.21 + * 12.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 12.23 + * or visit www.oracle.com if you need additional information or have any 12.24 + * questions. 12.25 + */ 12.26 + 12.27 +/* 12.28 + * @test 12.29 + * @bug 8029725 12.30 + * @summary Lambda reference to containing local class causes javac infinite recursion 12.31 + * @author Robert Field 12.32 + * @run main LambdaLocalTest 12.33 + */ 12.34 + 12.35 +public class LambdaLocalTest { 12.36 + interface F {void f();} 12.37 + 12.38 + static F f; 12.39 + static StringBuffer sb = new StringBuffer(); 12.40 + 12.41 + static void assertEquals(Object val, Object expected) { 12.42 + if (!val.equals(expected)) { 12.43 + throw new AssertionError("expected '" + expected + "' got '" + val + "'"); 12.44 + } 12.45 + } 12.46 + 12.47 + public static void main(String[] args) { 12.48 + class Local { 12.49 + public Local() { 12.50 + f = () -> new Local(); 12.51 + sb.append("+"); 12.52 + } 12.53 + } 12.54 + new Local(); 12.55 + f.f(); 12.56 + assertEquals(sb.toString(), "++"); 12.57 + } 12.58 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/tools/javac/lambda/LambdaMultiCatchTest.java Wed May 07 21:33:15 2014 -0700 13.3 @@ -0,0 +1,58 @@ 13.4 +/* 13.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.7 + * 13.8 + * This code is free software; you can redistribute it and/or modify it 13.9 + * under the terms of the GNU General Public License version 2 only, as 13.10 + * published by the Free Software Foundation. Oracle designates this 13.11 + * particular file as subject to the "Classpath" exception as provided 13.12 + * by Oracle in the LICENSE file that accompanied this code. 13.13 + * 13.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 13.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13.17 + * version 2 for more details (a copy is included in the LICENSE file that 13.18 + * accompanied this code). 13.19 + * 13.20 + * You should have received a copy of the GNU General Public License version 13.21 + * 2 along with this work; if not, write to the Free Software Foundation, 13.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 13.23 + * 13.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 13.25 + * or visit www.oracle.com if you need additional information or have any 13.26 + * questions. 13.27 + */ 13.28 + 13.29 +/** 13.30 + * @test 13.31 + * @bug 8036942 13.32 + * @summary javac generates incorrect exception table for multi-catch statements inside a lambda 13.33 + * @run main LambdaMultiCatchTest 13.34 + */ 13.35 + 13.36 +import java.io.IOException; 13.37 +import java.util.function.Function; 13.38 + 13.39 +public class LambdaMultiCatchTest { 13.40 + public static void main(String[] args) { 13.41 + Function<String,String> fi = x -> { 13.42 + String result = "nada"; 13.43 + try { 13.44 + switch (x) { 13.45 + case "IO": throw new IOException(); 13.46 + case "Illegal": throw new IllegalArgumentException(); 13.47 + case "Run": throw new RuntimeException(); 13.48 + } 13.49 + } catch (IOException|IllegalArgumentException ex) { 13.50 + result = "IO/Illegal"; 13.51 + } catch (Exception ex) { 13.52 + result = "Any"; 13.53 + }; 13.54 + return result; 13.55 + }; 13.56 + String val = fi.apply("Run"); 13.57 + if (!val.equals("Any")) { 13.58 + throw new AssertionError("Fail: Expected 'Any' but got '" + val + "'"); 13.59 + } 13.60 + } 13.61 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/tools/javac/lambda/LambdaOuterLocalTest.java Wed May 07 21:33:15 2014 -0700 14.3 @@ -0,0 +1,61 @@ 14.4 +/* 14.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.7 + * 14.8 + * This code is free software; you can redistribute it and/or modify it 14.9 + * under the terms of the GNU General Public License version 2 only, as 14.10 + * published by the Free Software Foundation. 14.11 + * 14.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.15 + * version 2 for more details (a copy is included in the LICENSE file that 14.16 + * accompanied this code). 14.17 + * 14.18 + * You should have received a copy of the GNU General Public License version 14.19 + * 2 along with this work; if not, write to the Free Software Foundation, 14.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.21 + * 14.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 14.23 + * or visit www.oracle.com if you need additional information or have any 14.24 + * questions. 14.25 + */ 14.26 + 14.27 +/* 14.28 + * @test 14.29 + * @bug 8029725 14.30 + * @summary Lambda reference to containing local class causes javac infinite recursion 14.31 + * @author Robert Field 14.32 + * @run main LambdaOuterLocalTest 14.33 + */ 14.34 + 14.35 +public class LambdaOuterLocalTest { 14.36 + interface F {void f();} 14.37 + 14.38 + static F f; 14.39 + static StringBuffer sb = new StringBuffer(); 14.40 + 14.41 + static void assertEquals(Object val, Object expected) { 14.42 + if (!val.equals(expected)) { 14.43 + throw new AssertionError("expected '" + expected + "' got '" + val + "'"); 14.44 + } 14.45 + } 14.46 + 14.47 + public static void main(String[] args) { 14.48 + class Local1 { 14.49 + public Local1() { 14.50 + class Local2 { 14.51 + public Local2() { 14.52 + f = () -> new Local1(); 14.53 + sb.append("2"); 14.54 + } 14.55 + } 14.56 + sb.append("1"); 14.57 + new Local2(); 14.58 + } 14.59 + } 14.60 + new Local1(); 14.61 + f.f(); 14.62 + assertEquals(sb.toString(), "1212"); 14.63 + } 14.64 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/tools/javac/lambda/SingleLocalTest.java Wed May 07 21:33:15 2014 -0700 15.3 @@ -0,0 +1,50 @@ 15.4 +/* 15.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 15.7 + * 15.8 + * This code is free software; you can redistribute it and/or modify it 15.9 + * under the terms of the GNU General Public License version 2 only, as 15.10 + * published by the Free Software Foundation. 15.11 + * 15.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 15.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15.15 + * version 2 for more details (a copy is included in the LICENSE file that 15.16 + * accompanied this code). 15.17 + * 15.18 + * You should have received a copy of the GNU General Public License version 15.19 + * 2 along with this work; if not, write to the Free Software Foundation, 15.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 15.21 + * 15.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 15.23 + * or visit www.oracle.com if you need additional information or have any 15.24 + * questions. 15.25 + */ 15.26 + 15.27 +/* 15.28 + * @test 15.29 + * @bug 8029852 15.30 + * @summary Bad code generated (VerifyError) when lambda instantiates 15.31 + * enclosing local class and has captured variables 15.32 + */ 15.33 +public class SingleLocalTest { 15.34 + interface F {void f();} 15.35 + 15.36 + static F f; 15.37 + 15.38 + public static void main(String[] args) { 15.39 + StringBuffer sb = new StringBuffer(); 15.40 + class Local1 { 15.41 + public Local1() { 15.42 + f = () -> new Local1(); 15.43 + sb.append("1"); 15.44 + } 15.45 + } 15.46 + new Local1(); 15.47 + f.f(); 15.48 + String s = sb.toString(); 15.49 + if (!s.equals("11")) { 15.50 + throw new AssertionError("Expected '11' got '" + s + "'"); 15.51 + } 15.52 + } 15.53 +}