Mon, 21 Jan 2013 20:13:56 +0000
8005244: Implement overload resolution as per latest spec EDR
Summary: Add support for stuck expressions and provisional applicability
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/code/Source.java Mon Jan 21 11:16:28 2013 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Source.java Mon Jan 21 20:13:56 2013 +0000 1.3 @@ -218,6 +218,12 @@ 1.4 public boolean allowIntersectionTypesInCast() { 1.5 return compareTo(JDK1_8) >= 0; 1.6 } 1.7 + public boolean allowEarlyReturnConstraints() { 1.8 + return compareTo(JDK1_8) >= 0; 1.9 + } 1.10 + public boolean allowStructuralMostSpecific() { 1.11 + return compareTo(JDK1_8) >= 0; 1.12 + } 1.13 public static SourceVersion toSourceVersion(Source source) { 1.14 switch(source) { 1.15 case JDK1_2:
2.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Mon Jan 21 11:16:28 2013 -0800 2.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Mon Jan 21 20:13:56 2013 +0000 2.3 @@ -354,8 +354,29 @@ 2.4 return descSym; 2.5 } 2.6 2.7 - public Type getType(Type origin) { 2.8 - return memberType(origin, descSym); 2.9 + public Type getType(Type site) { 2.10 + if (capture(site) != site) { 2.11 + Type formalInterface = site.tsym.type; 2.12 + ListBuffer<Type> typeargs = ListBuffer.lb(); 2.13 + List<Type> actualTypeargs = site.getTypeArguments(); 2.14 + //simply replace the wildcards with its bound 2.15 + for (Type t : formalInterface.getTypeArguments()) { 2.16 + if (actualTypeargs.head.hasTag(WILDCARD)) { 2.17 + WildcardType wt = (WildcardType)actualTypeargs.head; 2.18 + typeargs.append(wt.type); 2.19 + } else { 2.20 + typeargs.append(actualTypeargs.head); 2.21 + } 2.22 + actualTypeargs = actualTypeargs.tail; 2.23 + } 2.24 + site = subst(formalInterface, formalInterface.getTypeArguments(), typeargs.toList()); 2.25 + if (!chk.checkValidGenericType(site)) { 2.26 + //if the inferred functional interface type is not well-formed, 2.27 + //or if it's not a subtype of the original target, issue an error 2.28 + throw failure(diags.fragment("no.suitable.functional.intf.inst", site)); 2.29 + } 2.30 + } 2.31 + return memberType(site, descSym); 2.32 } 2.33 } 2.34 2.35 @@ -553,6 +574,15 @@ 2.36 return false; 2.37 } 2.38 } 2.39 + 2.40 + public boolean isFunctionalInterface(Type site) { 2.41 + try { 2.42 + findDescriptorType(site); 2.43 + return true; 2.44 + } catch (FunctionDescriptorLookupError ex) { 2.45 + return false; 2.46 + } 2.47 + } 2.48 // </editor-fold> 2.49 2.50 /**
3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Jan 21 11:16:28 2013 -0800 3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Jan 21 20:13:56 2013 +0000 3.3 @@ -48,6 +48,7 @@ 3.4 import com.sun.tools.javac.jvm.Target; 3.5 import com.sun.tools.javac.tree.*; 3.6 import com.sun.tools.javac.tree.JCTree.*; 3.7 +import com.sun.tools.javac.tree.JCTree.JCPolyExpression.*; 3.8 import com.sun.tools.javac.util.*; 3.9 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 3.10 import com.sun.tools.javac.util.List; 3.11 @@ -1376,18 +1377,19 @@ 3.12 public void visitConditional(JCConditional tree) { 3.13 Type condtype = attribExpr(tree.cond, env, syms.booleanType); 3.14 3.15 - boolean standaloneConditional = !allowPoly || 3.16 + tree.polyKind = (!allowPoly || 3.17 pt().hasTag(NONE) && pt() != Type.recoveryType || 3.18 - isBooleanOrNumeric(env, tree); 3.19 - 3.20 - if (!standaloneConditional && resultInfo.pt.hasTag(VOID)) { 3.21 + isBooleanOrNumeric(env, tree)) ? 3.22 + PolyKind.STANDALONE : PolyKind.POLY; 3.23 + 3.24 + if (tree.polyKind == PolyKind.POLY && resultInfo.pt.hasTag(VOID)) { 3.25 //cannot get here (i.e. it means we are returning from void method - which is already an error) 3.26 resultInfo.checkContext.report(tree, diags.fragment("conditional.target.cant.be.void")); 3.27 result = tree.type = types.createErrorType(resultInfo.pt); 3.28 return; 3.29 } 3.30 3.31 - ResultInfo condInfo = standaloneConditional ? 3.32 + ResultInfo condInfo = tree.polyKind == PolyKind.STANDALONE ? 3.33 unknownExprInfo : 3.34 resultInfo.dup(new Check.NestedCheckContext(resultInfo.checkContext) { 3.35 //this will use enclosing check context to check compatibility of 3.36 @@ -1402,7 +1404,7 @@ 3.37 Type truetype = attribTree(tree.truepart, env, condInfo); 3.38 Type falsetype = attribTree(tree.falsepart, env, condInfo); 3.39 3.40 - Type owntype = standaloneConditional ? condType(tree, truetype, falsetype) : pt(); 3.41 + Type owntype = (tree.polyKind == PolyKind.STANDALONE) ? condType(tree, truetype, falsetype) : pt(); 3.42 if (condtype.constValue() != null && 3.43 truetype.constValue() != null && 3.44 falsetype.constValue() != null && 3.45 @@ -1424,12 +1426,30 @@ 3.46 JCConditional condTree = (JCConditional)tree; 3.47 return isBooleanOrNumeric(env, condTree.truepart) && 3.48 isBooleanOrNumeric(env, condTree.falsepart); 3.49 + case APPLY: 3.50 + JCMethodInvocation speculativeMethodTree = 3.51 + (JCMethodInvocation)deferredAttr.attribSpeculative(tree, env, unknownExprInfo); 3.52 + Type owntype = TreeInfo.symbol(speculativeMethodTree.meth).type.getReturnType(); 3.53 + return types.unboxedTypeOrType(owntype).isPrimitive(); 3.54 + case NEWCLASS: 3.55 + JCExpression className = 3.56 + removeClassParams.translate(((JCNewClass)tree).clazz); 3.57 + JCExpression speculativeNewClassTree = 3.58 + (JCExpression)deferredAttr.attribSpeculative(className, env, unknownTypeInfo); 3.59 + return types.unboxedTypeOrType(speculativeNewClassTree.type).isPrimitive(); 3.60 default: 3.61 Type speculativeType = deferredAttr.attribSpeculative(tree, env, unknownExprInfo).type; 3.62 speculativeType = types.unboxedTypeOrType(speculativeType); 3.63 return speculativeType.isPrimitive(); 3.64 } 3.65 } 3.66 + //where 3.67 + TreeTranslator removeClassParams = new TreeTranslator() { 3.68 + @Override 3.69 + public void visitTypeApply(JCTypeApply tree) { 3.70 + result = translate(tree.clazz); 3.71 + } 3.72 + }; 3.73 3.74 /** Compute the type of a conditional expression, after 3.75 * checking that it exists. See JLS 15.25. Does not take into 3.76 @@ -2173,17 +2193,18 @@ 3.77 boolean needsRecovery = 3.78 resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK; 3.79 try { 3.80 + Type target = pt(); 3.81 List<Type> explicitParamTypes = null; 3.82 - if (TreeInfo.isExplicitLambda(that)) { 3.83 + if (that.paramKind == JCLambda.ParameterKind.EXPLICIT) { 3.84 //attribute lambda parameters 3.85 attribStats(that.params, localEnv); 3.86 explicitParamTypes = TreeInfo.types(that.params); 3.87 + target = infer.instantiateFunctionalInterface(that, target, explicitParamTypes, resultInfo.checkContext); 3.88 } 3.89 3.90 - Type target; 3.91 Type lambdaType; 3.92 if (pt() != Type.recoveryType) { 3.93 - target = infer.instantiateFunctionalInterface(that, checkIntersectionTarget(that, resultInfo), explicitParamTypes, resultInfo.checkContext); 3.94 + target = checkIntersectionTarget(that, target, resultInfo.checkContext); 3.95 lambdaType = types.findDescriptorType(target); 3.96 chk.checkFunctionalInterface(that, target); 3.97 } else { 3.98 @@ -2191,6 +2212,8 @@ 3.99 lambdaType = fallbackDescriptorType(that); 3.100 } 3.101 3.102 + setFunctionalInfo(that, pt(), lambdaType, resultInfo.checkContext.inferenceContext()); 3.103 + 3.104 if (lambdaType.hasTag(FORALL)) { 3.105 //lambda expression target desc cannot be a generic method 3.106 resultInfo.checkContext.report(that, diags.fragment("invalid.generic.lambda.target", 3.107 @@ -2199,7 +2222,7 @@ 3.108 return; 3.109 } 3.110 3.111 - if (!TreeInfo.isExplicitLambda(that)) { 3.112 + if (that.paramKind == JCLambda.ParameterKind.IMPLICIT) { 3.113 //add param type info in the AST 3.114 List<Type> actuals = lambdaType.getParameterTypes(); 3.115 List<JCVariableDecl> params = that.params; 3.116 @@ -2282,8 +2305,7 @@ 3.117 } 3.118 } 3.119 3.120 - private Type checkIntersectionTarget(DiagnosticPosition pos, ResultInfo resultInfo) { 3.121 - Type pt = resultInfo.pt; 3.122 + private Type checkIntersectionTarget(DiagnosticPosition pos, Type pt, CheckContext checkContext) { 3.123 if (pt != Type.recoveryType && pt.isCompound()) { 3.124 IntersectionClassType ict = (IntersectionClassType)pt; 3.125 List<Type> bounds = ict.allInterfaces ? 3.126 @@ -2292,7 +2314,7 @@ 3.127 types.findDescriptorType(bounds.head); //propagate exception outwards! 3.128 for (Type bound : bounds.tail) { 3.129 if (!types.isMarkerInterface(bound)) { 3.130 - resultInfo.checkContext.report(pos, diags.fragment("secondary.bound.must.be.marker.intf", bound)); 3.131 + checkContext.report(pos, diags.fragment("secondary.bound.must.be.marker.intf", bound)); 3.132 } 3.133 } 3.134 //for now (translation doesn't support intersection types) 3.135 @@ -2355,9 +2377,9 @@ 3.136 @Override 3.137 public boolean compatible(Type found, Type req, Warner warn) { 3.138 //return type must be compatible in both current context and assignment context 3.139 - return types.isAssignable(found, inferenceContext().asFree(req, types), warn) && 3.140 - super.compatible(found, req, warn); 3.141 + return chk.basicHandler.compatible(found, inferenceContext().asFree(req, types), warn); 3.142 } 3.143 + 3.144 @Override 3.145 public void report(DiagnosticPosition pos, JCDiagnostic details) { 3.146 enclosingContext.report(pos, diags.fragment("incompatible.ret.type.in.lambda", details)); 3.147 @@ -2473,7 +2495,7 @@ 3.148 Type target; 3.149 Type desc; 3.150 if (pt() != Type.recoveryType) { 3.151 - target = infer.instantiateFunctionalInterface(that, checkIntersectionTarget(that, resultInfo), null, resultInfo.checkContext); 3.152 + target = checkIntersectionTarget(that, pt(), resultInfo.checkContext); 3.153 desc = types.findDescriptorType(target); 3.154 chk.checkFunctionalInterface(that, target); 3.155 } else { 3.156 @@ -2481,12 +2503,11 @@ 3.157 desc = fallbackDescriptorType(that); 3.158 } 3.159 3.160 + setFunctionalInfo(that, pt(), desc, resultInfo.checkContext.inferenceContext()); 3.161 List<Type> argtypes = desc.getParameterTypes(); 3.162 3.163 - boolean allowBoxing = 3.164 - resultInfo.checkContext.deferredAttrContext().phase.isBoxingRequired(); 3.165 Pair<Symbol, Resolve.ReferenceLookupHelper> refResult = rs.resolveMemberReference(that.pos(), localEnv, that, 3.166 - that.expr.type, that.name, argtypes, typeargtypes, allowBoxing); 3.167 + that.expr.type, that.name, argtypes, typeargtypes, true); 3.168 3.169 Symbol refSym = refResult.fst; 3.170 Resolve.ReferenceLookupHelper lookupHelper = refResult.snd; 3.171 @@ -2635,6 +2656,34 @@ 3.172 } 3.173 } 3.174 3.175 + /** 3.176 + * Set functional type info on the underlying AST. Note: as the target descriptor 3.177 + * might contain inference variables, we might need to register an hook in the 3.178 + * current inference context. 3.179 + */ 3.180 + private void setFunctionalInfo(final JCFunctionalExpression fExpr, final Type pt, final Type descriptorType, InferenceContext inferenceContext) { 3.181 + if (inferenceContext.free(descriptorType)) { 3.182 + inferenceContext.addFreeTypeListener(List.of(pt, descriptorType), new FreeTypeListener() { 3.183 + public void typesInferred(InferenceContext inferenceContext) { 3.184 + setFunctionalInfo(fExpr, pt, inferenceContext.asInstType(descriptorType, types), inferenceContext); 3.185 + } 3.186 + }); 3.187 + } else { 3.188 + ListBuffer<TypeSymbol> targets = ListBuffer.lb(); 3.189 + if (pt.hasTag(CLASS)) { 3.190 + if (pt.isCompound()) { 3.191 + for (Type t : ((IntersectionClassType)pt()).interfaces_field) { 3.192 + targets.append(t.tsym); 3.193 + } 3.194 + } else { 3.195 + targets.append(pt.tsym); 3.196 + } 3.197 + } 3.198 + fExpr.targets = targets.toList(); 3.199 + fExpr.descriptorType = descriptorType; 3.200 + } 3.201 + } 3.202 + 3.203 public void visitParens(JCParens tree) { 3.204 Type owntype = attribTree(tree.expr, env, resultInfo); 3.205 result = check(tree, owntype, pkind(), resultInfo); 3.206 @@ -4078,11 +4127,28 @@ 3.207 } 3.208 3.209 @Override 3.210 + public void visitLambda(JCLambda that) { 3.211 + super.visitLambda(that); 3.212 + if (that.descriptorType == null) { 3.213 + that.descriptorType = syms.unknownType; 3.214 + } 3.215 + if (that.targets == null) { 3.216 + that.targets = List.nil(); 3.217 + } 3.218 + } 3.219 + 3.220 + @Override 3.221 public void visitReference(JCMemberReference that) { 3.222 super.visitReference(that); 3.223 if (that.sym == null) { 3.224 that.sym = new MethodSymbol(0, names.empty, syms.unknownType, syms.noSymbol); 3.225 } 3.226 + if (that.descriptorType == null) { 3.227 + that.descriptorType = syms.unknownType; 3.228 + } 3.229 + if (that.targets == null) { 3.230 + that.targets = List.nil(); 3.231 + } 3.232 } 3.233 } 3.234 // </editor-fold>
4.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Mon Jan 21 11:16:28 2013 -0800 4.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Mon Jan 21 20:13:56 2013 +0000 4.3 @@ -36,7 +36,6 @@ 4.4 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 4.5 import com.sun.tools.javac.util.List; 4.6 4.7 -import com.sun.tools.javac.tree.JCTree.*; 4.8 import com.sun.tools.javac.code.Lint; 4.9 import com.sun.tools.javac.code.Lint.LintCategory; 4.10 import com.sun.tools.javac.code.Type.*; 4.11 @@ -44,6 +43,8 @@ 4.12 import com.sun.tools.javac.comp.DeferredAttr.DeferredAttrContext; 4.13 import com.sun.tools.javac.comp.Infer.InferenceContext; 4.14 import com.sun.tools.javac.comp.Infer.InferenceContext.FreeTypeListener; 4.15 +import com.sun.tools.javac.tree.JCTree.*; 4.16 +import com.sun.tools.javac.tree.JCTree.JCPolyExpression.*; 4.17 4.18 import static com.sun.tools.javac.code.Flags.*; 4.19 import static com.sun.tools.javac.code.Flags.ANNOTATION; 4.20 @@ -900,7 +901,6 @@ 4.21 syms.methodClass); 4.22 } 4.23 if (useVarargs) { 4.24 - JCTree tree = env.tree; 4.25 Type argtype = owntype.getParameterTypes().last(); 4.26 if (!types.isReifiable(argtype) && 4.27 (!allowSimplifiedVarargs || 4.28 @@ -911,22 +911,13 @@ 4.29 argtype); 4.30 } 4.31 if (!((MethodSymbol)sym.baseSymbol()).isSignaturePolymorphic(types)) { 4.32 - Type elemtype = types.elemtype(argtype); 4.33 - switch (tree.getTag()) { 4.34 - case APPLY: 4.35 - ((JCMethodInvocation) tree).varargsElement = elemtype; 4.36 - break; 4.37 - case NEWCLASS: 4.38 - ((JCNewClass) tree).varargsElement = elemtype; 4.39 - break; 4.40 - case REFERENCE: 4.41 - ((JCMemberReference) tree).varargsElement = elemtype; 4.42 - break; 4.43 - default: 4.44 - throw new AssertionError(""+tree); 4.45 - } 4.46 + TreeInfo.setVarargsElement(env.tree, types.elemtype(argtype)); 4.47 } 4.48 } 4.49 + PolyKind pkind = (sym.type.hasTag(FORALL) && 4.50 + sym.type.getReturnType().containsAny(((ForAll)sym.type).tvars)) ? 4.51 + PolyKind.POLY : PolyKind.STANDALONE; 4.52 + TreeInfo.setPolyKind(env.tree, pkind); 4.53 return owntype; 4.54 } 4.55 //where
5.1 --- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Mon Jan 21 11:16:28 2013 -0800 5.2 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Mon Jan 21 20:13:56 2013 +0000 5.3 @@ -65,6 +65,7 @@ 5.4 5.5 final Attr attr; 5.6 final Check chk; 5.7 + final JCDiagnostic.Factory diags; 5.8 final Enter enter; 5.9 final Infer infer; 5.10 final Log log; 5.11 @@ -83,14 +84,20 @@ 5.12 context.put(deferredAttrKey, this); 5.13 attr = Attr.instance(context); 5.14 chk = Check.instance(context); 5.15 + diags = JCDiagnostic.Factory.instance(context); 5.16 enter = Enter.instance(context); 5.17 infer = Infer.instance(context); 5.18 log = Log.instance(context); 5.19 syms = Symtab.instance(context); 5.20 make = TreeMaker.instance(context); 5.21 types = Types.instance(context); 5.22 + Names names = Names.instance(context); 5.23 + stuckTree = make.Ident(names.empty).setType(Type.noType); 5.24 } 5.25 5.26 + /** shared tree for stuck expressions */ 5.27 + final JCTree stuckTree; 5.28 + 5.29 /** 5.30 * This type represents a deferred type. A deferred type starts off with 5.31 * no information on the underlying expression type. Such info needs to be 5.32 @@ -356,12 +363,11 @@ 5.33 //scan a defensive copy of the node list - this is because a deferred 5.34 //attribution round can add new nodes to the list 5.35 for (DeferredAttrNode deferredAttrNode : List.from(deferredAttrNodes)) { 5.36 - if (!deferredAttrNode.isStuck()) { 5.37 - deferredAttrNode.process(); 5.38 + if (!deferredAttrNode.process()) { 5.39 + stuckVars.addAll(deferredAttrNode.stuckVars); 5.40 + } else { 5.41 deferredAttrNodes.remove(deferredAttrNode); 5.42 progress = true; 5.43 - } else { 5.44 - stuckVars.addAll(deferredAttrNode.stuckVars); 5.45 } 5.46 } 5.47 if (!progress) { 5.48 @@ -404,21 +410,88 @@ 5.49 } 5.50 5.51 /** 5.52 - * is this node stuck? 5.53 + * Process a deferred attribution node. 5.54 + * Invariant: a stuck node cannot be processed. 5.55 */ 5.56 - boolean isStuck() { 5.57 - return stuckVars.nonEmpty(); 5.58 + @SuppressWarnings("fallthrough") 5.59 + boolean process() { 5.60 + switch (mode) { 5.61 + case SPECULATIVE: 5.62 + dt.check(resultInfo, List.<Type>nil(), new StructuralStuckChecker()); 5.63 + return true; 5.64 + case CHECK: 5.65 + if (stuckVars.nonEmpty()) { 5.66 + return false; 5.67 + } else { 5.68 + dt.check(resultInfo, stuckVars, basicCompleter); 5.69 + return true; 5.70 + } 5.71 + default: 5.72 + throw new AssertionError("Bad mode"); 5.73 + } 5.74 } 5.75 5.76 /** 5.77 - * Process a deferred attribution node. 5.78 - * Invariant: a stuck node cannot be processed. 5.79 + * Structural checker for stuck expressions 5.80 */ 5.81 - void process() { 5.82 - if (isStuck()) { 5.83 - throw new IllegalStateException("Cannot process a stuck deferred node"); 5.84 + class StructuralStuckChecker extends TreeScanner implements DeferredTypeCompleter { 5.85 + 5.86 + ResultInfo resultInfo; 5.87 + 5.88 + public Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) { 5.89 + this.resultInfo = resultInfo; 5.90 + dt.tree.accept(this); 5.91 + dt.speculativeCache.put(msym, stuckTree, phase); 5.92 + return Type.noType; 5.93 } 5.94 - dt.check(resultInfo); 5.95 + 5.96 + @Override 5.97 + public void visitLambda(JCLambda tree) { 5.98 + Check.CheckContext checkContext = resultInfo.checkContext; 5.99 + Type pt = resultInfo.pt; 5.100 + if (inferenceContext.inferencevars.contains(pt)) { 5.101 + //ok 5.102 + return; 5.103 + } else { 5.104 + //must be a functional descriptor 5.105 + try { 5.106 + Type desc = types.findDescriptorType(pt); 5.107 + if (desc.getParameterTypes().length() != tree.params.length()) { 5.108 + checkContext.report(tree, diags.fragment("incompatible.arg.types.in.lambda")); 5.109 + } 5.110 + } catch (Types.FunctionDescriptorLookupError ex) { 5.111 + checkContext.report(null, ex.getDiagnostic()); 5.112 + } 5.113 + } 5.114 + } 5.115 + 5.116 + @Override 5.117 + public void visitNewClass(JCNewClass tree) { 5.118 + //do nothing 5.119 + } 5.120 + 5.121 + @Override 5.122 + public void visitApply(JCMethodInvocation tree) { 5.123 + //do nothing 5.124 + } 5.125 + 5.126 + @Override 5.127 + public void visitReference(JCMemberReference tree) { 5.128 + Check.CheckContext checkContext = resultInfo.checkContext; 5.129 + Type pt = resultInfo.pt; 5.130 + if (inferenceContext.inferencevars.contains(pt)) { 5.131 + //ok 5.132 + return; 5.133 + } else { 5.134 + try { 5.135 + //TODO: we should speculative determine if there's a match 5.136 + //based on arity - if yes, method is applicable. 5.137 + types.findDescriptorType(pt); 5.138 + } catch (Types.FunctionDescriptorLookupError ex) { 5.139 + checkContext.report(null, ex.getDiagnostic()); 5.140 + } 5.141 + } 5.142 + } 5.143 } 5.144 } 5.145 } 5.146 @@ -624,12 +697,12 @@ 5.147 if (inferenceContext.inferenceVars().contains(pt)) { 5.148 stuckVars.add(pt); 5.149 } 5.150 - if (!types.isFunctionalInterface(pt.tsym)) { 5.151 + if (!types.isFunctionalInterface(pt)) { 5.152 return; 5.153 } 5.154 Type descType = types.findDescriptorType(pt); 5.155 List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes()); 5.156 - if (!TreeInfo.isExplicitLambda(tree) && 5.157 + if (tree.paramKind == JCLambda.ParameterKind.IMPLICIT && 5.158 freeArgVars.nonEmpty()) { 5.159 stuckVars.addAll(freeArgVars); 5.160 } 5.161 @@ -643,7 +716,7 @@ 5.162 stuckVars.add(pt); 5.163 return; 5.164 } 5.165 - if (!types.isFunctionalInterface(pt.tsym)) { 5.166 + if (!types.isFunctionalInterface(pt)) { 5.167 return; 5.168 } 5.169
6.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Mon Jan 21 11:16:28 2013 -0800 6.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Mon Jan 21 20:13:56 2013 +0000 6.3 @@ -66,6 +66,9 @@ 6.4 Log log; 6.5 JCDiagnostic.Factory diags; 6.6 6.7 + /** Should we inject return-type constraints earlier? */ 6.8 + boolean allowEarlyReturnConstraints; 6.9 + 6.10 public static Infer instance(Context context) { 6.11 Infer instance = context.get(inferKey); 6.12 if (instance == null) 6.13 @@ -83,6 +86,7 @@ 6.14 chk = Check.instance(context); 6.15 diags = JCDiagnostic.Factory.instance(context); 6.16 inferenceException = new InferenceException(diags); 6.17 + allowEarlyReturnConstraints = Source.instance(context).allowEarlyReturnConstraints(); 6.18 } 6.19 6.20 /** 6.21 @@ -188,19 +192,6 @@ 6.22 MethodType mtype, 6.23 Attr.ResultInfo resultInfo, 6.24 Warner warn) throws InferenceException { 6.25 - Type to = resultInfo.pt; 6.26 - if (to.hasTag(NONE) || resultInfo.checkContext.inferenceContext().free(resultInfo.pt)) { 6.27 - to = mtype.getReturnType().isPrimitiveOrVoid() ? 6.28 - mtype.getReturnType() : syms.objectType; 6.29 - } 6.30 - Type qtype1 = inferenceContext.asFree(mtype.getReturnType(), types); 6.31 - if (!types.isSubtype(qtype1, 6.32 - qtype1.hasTag(UNDETVAR) ? types.boxedTypeOrType(to) : to)) { 6.33 - throw inferenceException 6.34 - .setMessage("infer.no.conforming.instance.exists", 6.35 - inferenceContext.restvars(), mtype.getReturnType(), to); 6.36 - } 6.37 - 6.38 while (true) { 6.39 boolean stuck = true; 6.40 for (Type t : inferenceContext.undetvars) { 6.41 @@ -283,6 +274,11 @@ 6.42 try { 6.43 methodCheck.argumentsAcceptable(env, deferredAttrContext, argtypes, mt.getParameterTypes(), warn); 6.44 6.45 + if (resultInfo != null && allowEarlyReturnConstraints && 6.46 + !warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED)) { 6.47 + generateReturnConstraints(mt, inferenceContext, resultInfo); 6.48 + } 6.49 + 6.50 deferredAttrContext.complete(); 6.51 6.52 // minimize as yet undetermined type variables 6.53 @@ -298,6 +294,9 @@ 6.54 6.55 if (!restvars.isEmpty()) { 6.56 if (resultInfo != null && !warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED)) { 6.57 + if (!allowEarlyReturnConstraints) { 6.58 + generateReturnConstraints(mt, inferenceContext, resultInfo); 6.59 + } 6.60 instantiateUninferred(env.tree.pos(), inferenceContext, mt, resultInfo, warn); 6.61 checkWithinBounds(inferenceContext, warn); 6.62 mt = (MethodType)inferenceContext.asInstType(mt, types); 6.63 @@ -313,6 +312,23 @@ 6.64 inferenceContext.notifyChange(types); 6.65 } 6.66 } 6.67 + //where 6.68 + void generateReturnConstraints(Type mt, InferenceContext inferenceContext, Attr.ResultInfo resultInfo) { 6.69 + if (resultInfo != null) { 6.70 + Type to = resultInfo.pt; 6.71 + if (to.hasTag(NONE) || resultInfo.checkContext.inferenceContext().free(resultInfo.pt)) { 6.72 + to = mt.getReturnType().isPrimitiveOrVoid() ? 6.73 + mt.getReturnType() : syms.objectType; 6.74 + } 6.75 + Type qtype1 = inferenceContext.asFree(mt.getReturnType(), types); 6.76 + if (!types.isSubtype(qtype1, 6.77 + qtype1.hasTag(UNDETVAR) ? types.boxedTypeOrType(to) : to)) { 6.78 + throw inferenceException 6.79 + .setMessage("infer.no.conforming.instance.exists", 6.80 + inferenceContext.restvars(), mt.getReturnType(), to); 6.81 + } 6.82 + } 6.83 + } 6.84 6.85 /** check that type parameters are within their bounds. 6.86 */ 6.87 @@ -461,52 +477,40 @@ 6.88 Type formalInterface = funcInterface.tsym.type; 6.89 InferenceContext funcInterfaceContext = 6.90 new InferenceContext(funcInterface.tsym.type.getTypeArguments(), this, false); 6.91 - if (paramTypes != null) { 6.92 - //get constraints from explicit params (this is done by 6.93 - //checking that explicit param types are equal to the ones 6.94 - //in the functional interface descriptors) 6.95 - List<Type> descParameterTypes = types.findDescriptorType(formalInterface).getParameterTypes(); 6.96 - if (descParameterTypes.size() != paramTypes.size()) { 6.97 - checkContext.report(pos, diags.fragment("incompatible.arg.types.in.lambda")); 6.98 + Assert.check(paramTypes != null); 6.99 + //get constraints from explicit params (this is done by 6.100 + //checking that explicit param types are equal to the ones 6.101 + //in the functional interface descriptors) 6.102 + List<Type> descParameterTypes = types.findDescriptorType(formalInterface).getParameterTypes(); 6.103 + if (descParameterTypes.size() != paramTypes.size()) { 6.104 + checkContext.report(pos, diags.fragment("incompatible.arg.types.in.lambda")); 6.105 + return types.createErrorType(funcInterface); 6.106 + } 6.107 + for (Type p : descParameterTypes) { 6.108 + if (!types.isSameType(funcInterfaceContext.asFree(p, types), paramTypes.head)) { 6.109 + checkContext.report(pos, diags.fragment("no.suitable.functional.intf.inst", funcInterface)); 6.110 return types.createErrorType(funcInterface); 6.111 } 6.112 - for (Type p : descParameterTypes) { 6.113 - if (!types.isSameType(funcInterfaceContext.asFree(p, types), paramTypes.head)) { 6.114 - checkContext.report(pos, diags.fragment("no.suitable.functional.intf.inst", funcInterface)); 6.115 - return types.createErrorType(funcInterface); 6.116 - } 6.117 - paramTypes = paramTypes.tail; 6.118 + paramTypes = paramTypes.tail; 6.119 + } 6.120 + List<Type> actualTypeargs = funcInterface.getTypeArguments(); 6.121 + for (Type t : funcInterfaceContext.undetvars) { 6.122 + UndetVar uv = (UndetVar)t; 6.123 + minimizeInst(uv, types.noWarnings); 6.124 + if (uv.inst == null && 6.125 + Type.filter(uv.getBounds(InferenceBound.UPPER), boundFilter).nonEmpty()) { 6.126 + maximizeInst(uv, types.noWarnings); 6.127 } 6.128 - for (Type t : funcInterfaceContext.undetvars) { 6.129 - UndetVar uv = (UndetVar)t; 6.130 - minimizeInst(uv, types.noWarnings); 6.131 - if (uv.inst == null && 6.132 - Type.filter(uv.getBounds(InferenceBound.UPPER), boundFilter).nonEmpty()) { 6.133 - maximizeInst(uv, types.noWarnings); 6.134 - } 6.135 - } 6.136 - 6.137 - formalInterface = funcInterfaceContext.asInstType(formalInterface, types); 6.138 - } 6.139 - ListBuffer<Type> typeargs = ListBuffer.lb(); 6.140 - List<Type> actualTypeargs = funcInterface.getTypeArguments(); 6.141 - //for remaining uninferred type-vars in the functional interface type, 6.142 - //simply replace the wildcards with its bound 6.143 - for (Type t : formalInterface.getTypeArguments()) { 6.144 - if (actualTypeargs.head.hasTag(WILDCARD)) { 6.145 - WildcardType wt = (WildcardType)actualTypeargs.head; 6.146 - typeargs.append(wt.type); 6.147 - } else { 6.148 - typeargs.append(actualTypeargs.head); 6.149 + if (uv.inst == null) { 6.150 + uv.inst = actualTypeargs.head; 6.151 } 6.152 actualTypeargs = actualTypeargs.tail; 6.153 } 6.154 - Type owntype = types.subst(formalInterface, funcInterfaceContext.inferenceVars(), typeargs.toList()); 6.155 + Type owntype = funcInterfaceContext.asInstType(formalInterface, types); 6.156 if (!chk.checkValidGenericType(owntype)) { 6.157 //if the inferred functional interface type is not well-formed, 6.158 //or if it's not a subtype of the original target, issue an error 6.159 checkContext.report(pos, diags.fragment("no.suitable.functional.intf.inst", funcInterface)); 6.160 - return types.createErrorType(funcInterface); 6.161 } 6.162 return owntype; 6.163 }
7.1 --- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Mon Jan 21 11:16:28 2013 -0800 7.2 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Mon Jan 21 20:13:56 2013 +0000 7.3 @@ -253,7 +253,7 @@ 7.4 int refKind = referenceKind(sym); 7.5 7.6 //convert to an invokedynamic call 7.7 - result = makeMetaFactoryIndyCall(tree, tree.targetType, refKind, sym, indy_args); 7.8 + result = makeMetaFactoryIndyCall(tree, refKind, sym, indy_args); 7.9 } 7.10 7.11 private JCIdent makeThis(Type type, Symbol owner) { 7.12 @@ -314,7 +314,7 @@ 7.13 7.14 7.15 //build a sam instance using an indy call to the meta-factory 7.16 - result = makeMetaFactoryIndyCall(tree, tree.targetType, localContext.referenceKind(), refSym, indy_args); 7.17 + result = makeMetaFactoryIndyCall(tree, localContext.referenceKind(), refSym, indy_args); 7.18 } 7.19 7.20 /** 7.21 @@ -503,19 +503,6 @@ 7.22 7.23 // </editor-fold> 7.24 7.25 - private MethodSymbol makeSamDescriptor(Type targetType) { 7.26 - return (MethodSymbol)types.findDescriptorSymbol(targetType.tsym); 7.27 - } 7.28 - 7.29 - private Type makeFunctionalDescriptorType(Type targetType, MethodSymbol samDescriptor, boolean erased) { 7.30 - Type descType = types.memberType(targetType, samDescriptor); 7.31 - return erased ? types.erasure(descType) : descType; 7.32 - } 7.33 - 7.34 - private Type makeFunctionalDescriptorType(Type targetType, boolean erased) { 7.35 - return makeFunctionalDescriptorType(targetType, makeSamDescriptor(targetType), erased); 7.36 - } 7.37 - 7.38 /** 7.39 * Generate an adapter method "bridge" for a method reference which cannot 7.40 * be used directly. 7.41 @@ -698,12 +685,12 @@ 7.42 /** 7.43 * Generate an indy method call to the meta factory 7.44 */ 7.45 - private JCExpression makeMetaFactoryIndyCall(JCExpression tree, Type targetType, int refKind, Symbol refSym, List<JCExpression> indy_args) { 7.46 + private JCExpression makeMetaFactoryIndyCall(JCFunctionalExpression tree, int refKind, Symbol refSym, List<JCExpression> indy_args) { 7.47 //determine the static bsm args 7.48 - Type mtype = makeFunctionalDescriptorType(targetType, true); 7.49 + Type mtype = types.erasure(tree.descriptorType); 7.50 + MethodSymbol samSym = (MethodSymbol) types.findDescriptorSymbol(tree.type.tsym); 7.51 List<Object> staticArgs = List.<Object>of( 7.52 - new Pool.MethodHandle(ClassFile.REF_invokeInterface, 7.53 - types.findDescriptorSymbol(targetType.tsym), types), 7.54 + new Pool.MethodHandle(ClassFile.REF_invokeInterface, types.findDescriptorSymbol(tree.type.tsym), types), 7.55 new Pool.MethodHandle(refKind, refSym, types), 7.56 new MethodType(mtype.getParameterTypes(), 7.57 mtype.getReturnType(), 7.58 @@ -1165,7 +1152,7 @@ 7.59 * This class is used to store important information regarding translation of 7.60 * lambda expression/method references (see subclasses). 7.61 */ 7.62 - private abstract class TranslationContext<T extends JCTree> { 7.63 + private abstract class TranslationContext<T extends JCFunctionalExpression> { 7.64 7.65 /** the underlying (untranslated) tree */ 7.66 T tree; 7.67 @@ -1329,7 +1316,7 @@ 7.68 } 7.69 7.70 Type generatedLambdaSig() { 7.71 - return types.erasure(types.findDescriptorType(tree.targetType)); 7.72 + return types.erasure(tree.descriptorType); 7.73 } 7.74 } 7.75 7.76 @@ -1385,7 +1372,7 @@ 7.77 } 7.78 7.79 Type bridgedRefSig() { 7.80 - return types.erasure(types.findDescriptorSymbol(tree.targetType.tsym).type); 7.81 + return types.erasure(types.findDescriptorSymbol(tree.targets.head).type); 7.82 } 7.83 } 7.84 }
8.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Mon Jan 21 11:16:28 2013 -0800 8.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Mon Jan 21 20:13:56 2013 +0000 8.3 @@ -41,6 +41,7 @@ 8.4 import com.sun.tools.javac.tree.*; 8.5 import com.sun.tools.javac.tree.JCTree.*; 8.6 import com.sun.tools.javac.tree.JCTree.JCMemberReference.ReferenceKind; 8.7 +import com.sun.tools.javac.tree.JCTree.JCPolyExpression.*; 8.8 import com.sun.tools.javac.util.*; 8.9 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; 8.10 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 8.11 @@ -92,6 +93,7 @@ 8.12 public final boolean varargsEnabled; // = source.allowVarargs(); 8.13 public final boolean allowMethodHandles; 8.14 public final boolean allowDefaultMethods; 8.15 + public final boolean allowStructuralMostSpecific; 8.16 private final boolean debugResolve; 8.17 final EnumSet<VerboseResolutionMode> verboseResolutionMode; 8.18 8.19 @@ -127,6 +129,7 @@ 8.20 Target target = Target.instance(context); 8.21 allowMethodHandles = target.hasMethodHandles(); 8.22 allowDefaultMethods = source.allowDefaultMethods(); 8.23 + allowStructuralMostSpecific = source.allowStructuralMostSpecific(); 8.24 polymorphicSignatureScope = new Scope(syms.noSymbol); 8.25 8.26 inapplicableMethodException = new InapplicableMethodException(diags); 8.27 @@ -835,6 +838,213 @@ 8.28 } 8.29 } 8.30 8.31 + /** 8.32 + * Most specific method applicability routine. Given a list of actual types A, 8.33 + * a list of formal types F1, and a list of formal types F2, the routine determines 8.34 + * as to whether the types in F1 can be considered more specific than those in F2 w.r.t. 8.35 + * argument types A. 8.36 + */ 8.37 + class MostSpecificCheck implements MethodCheck { 8.38 + 8.39 + boolean strict; 8.40 + List<Type> actuals; 8.41 + 8.42 + MostSpecificCheck(boolean strict, List<Type> actuals) { 8.43 + this.strict = strict; 8.44 + this.actuals = actuals; 8.45 + } 8.46 + 8.47 + @Override 8.48 + public void argumentsAcceptable(final Env<AttrContext> env, 8.49 + DeferredAttrContext deferredAttrContext, 8.50 + List<Type> formals1, 8.51 + List<Type> formals2, 8.52 + Warner warn) { 8.53 + formals2 = adjustArgs(formals2, deferredAttrContext.msym, formals1.length(), deferredAttrContext.phase.isVarargsRequired()); 8.54 + while (formals2.nonEmpty()) { 8.55 + ResultInfo mresult = methodCheckResult(formals2.head, deferredAttrContext, warn, actuals.head); 8.56 + mresult.check(null, formals1.head); 8.57 + formals1 = formals1.tail; 8.58 + formals2 = formals2.tail; 8.59 + actuals = actuals.isEmpty() ? actuals : actuals.tail; 8.60 + } 8.61 + } 8.62 + 8.63 + /** 8.64 + * Create a method check context to be used during the most specific applicability check 8.65 + */ 8.66 + ResultInfo methodCheckResult(Type to, DeferredAttr.DeferredAttrContext deferredAttrContext, 8.67 + Warner rsWarner, Type actual) { 8.68 + return attr.new ResultInfo(Kinds.VAL, to, 8.69 + new MostSpecificCheckContext(strict, deferredAttrContext, rsWarner, actual)); 8.70 + } 8.71 + 8.72 + /** 8.73 + * Subclass of method check context class that implements most specific 8.74 + * method conversion. If the actual type under analysis is a deferred type 8.75 + * a full blown structural analysis is carried out. 8.76 + */ 8.77 + class MostSpecificCheckContext extends MethodCheckContext { 8.78 + 8.79 + Type actual; 8.80 + 8.81 + public MostSpecificCheckContext(boolean strict, DeferredAttrContext deferredAttrContext, Warner rsWarner, Type actual) { 8.82 + super(strict, deferredAttrContext, rsWarner); 8.83 + this.actual = actual; 8.84 + } 8.85 + 8.86 + public boolean compatible(Type found, Type req, Warner warn) { 8.87 + if (!allowStructuralMostSpecific || actual == null) { 8.88 + return super.compatible(found, req, warn); 8.89 + } else { 8.90 + switch (actual.getTag()) { 8.91 + case DEFERRED: 8.92 + DeferredType dt = (DeferredType) actual; 8.93 + DeferredType.SpeculativeCache.Entry e = dt.speculativeCache.get(deferredAttrContext.msym, deferredAttrContext.phase); 8.94 + return (e == null || e.speculativeTree == deferredAttr.stuckTree) 8.95 + ? false : mostSpecific(found, req, e.speculativeTree, warn); 8.96 + default: 8.97 + return standaloneMostSpecific(found, req, actual, warn); 8.98 + } 8.99 + } 8.100 + } 8.101 + 8.102 + private boolean mostSpecific(Type t, Type s, JCTree tree, Warner warn) { 8.103 + MostSpecificChecker msc = new MostSpecificChecker(t, s, warn); 8.104 + msc.scan(tree); 8.105 + return msc.result; 8.106 + } 8.107 + 8.108 + boolean polyMostSpecific(Type t1, Type t2, Warner warn) { 8.109 + return (!t1.isPrimitive() && t2.isPrimitive()) 8.110 + ? true : super.compatible(t1, t2, warn); 8.111 + } 8.112 + 8.113 + boolean standaloneMostSpecific(Type t1, Type t2, Type exprType, Warner warn) { 8.114 + return (exprType.isPrimitive() == t1.isPrimitive() 8.115 + && exprType.isPrimitive() != t2.isPrimitive()) 8.116 + ? true : super.compatible(t1, t2, warn); 8.117 + } 8.118 + 8.119 + /** 8.120 + * Structural checker for most specific. 8.121 + */ 8.122 + class MostSpecificChecker extends DeferredAttr.PolyScanner { 8.123 + 8.124 + final Type t; 8.125 + final Type s; 8.126 + final Warner warn; 8.127 + boolean result; 8.128 + 8.129 + MostSpecificChecker(Type t, Type s, Warner warn) { 8.130 + this.t = t; 8.131 + this.s = s; 8.132 + this.warn = warn; 8.133 + result = true; 8.134 + } 8.135 + 8.136 + @Override 8.137 + void skip(JCTree tree) { 8.138 + result &= standaloneMostSpecific(t, s, tree.type, warn); 8.139 + } 8.140 + 8.141 + @Override 8.142 + public void visitConditional(JCConditional tree) { 8.143 + if (tree.polyKind == PolyKind.STANDALONE) { 8.144 + result &= standaloneMostSpecific(t, s, tree.type, warn); 8.145 + } else { 8.146 + super.visitConditional(tree); 8.147 + } 8.148 + } 8.149 + 8.150 + @Override 8.151 + public void visitApply(JCMethodInvocation tree) { 8.152 + result &= (tree.polyKind == PolyKind.STANDALONE) 8.153 + ? standaloneMostSpecific(t, s, tree.type, warn) 8.154 + : polyMostSpecific(t, s, warn); 8.155 + } 8.156 + 8.157 + @Override 8.158 + public void visitNewClass(JCNewClass tree) { 8.159 + result &= (tree.polyKind == PolyKind.STANDALONE) 8.160 + ? standaloneMostSpecific(t, s, tree.type, warn) 8.161 + : polyMostSpecific(t, s, warn); 8.162 + } 8.163 + 8.164 + @Override 8.165 + public void visitReference(JCMemberReference tree) { 8.166 + if (types.isFunctionalInterface(t.tsym) && 8.167 + types.isFunctionalInterface(s.tsym) && 8.168 + types.asSuper(t, s.tsym) == null && 8.169 + types.asSuper(s, t.tsym) == null) { 8.170 + Type desc_t = types.findDescriptorType(t); 8.171 + Type desc_s = types.findDescriptorType(s); 8.172 + if (types.isSameTypes(desc_t.getParameterTypes(), desc_s.getParameterTypes())) { 8.173 + if (!desc_s.getReturnType().hasTag(VOID)) { 8.174 + //perform structural comparison 8.175 + Type ret_t = desc_t.getReturnType(); 8.176 + Type ret_s = desc_s.getReturnType(); 8.177 + result &= ((tree.refPolyKind == PolyKind.STANDALONE) 8.178 + ? standaloneMostSpecific(ret_t, ret_s, tree.type, warn) 8.179 + : polyMostSpecific(ret_t, ret_s, warn)); 8.180 + } else { 8.181 + return; 8.182 + } 8.183 + } else { 8.184 + result &= false; 8.185 + } 8.186 + } else { 8.187 + result &= MostSpecificCheckContext.super.compatible(t, s, warn); 8.188 + } 8.189 + } 8.190 + 8.191 + @Override 8.192 + public void visitLambda(JCLambda tree) { 8.193 + if (types.isFunctionalInterface(t.tsym) && 8.194 + types.isFunctionalInterface(s.tsym) && 8.195 + types.asSuper(t, s.tsym) == null && 8.196 + types.asSuper(s, t.tsym) == null) { 8.197 + Type desc_t = types.findDescriptorType(t); 8.198 + Type desc_s = types.findDescriptorType(s); 8.199 + if (tree.paramKind == JCLambda.ParameterKind.EXPLICIT 8.200 + || types.isSameTypes(desc_t.getParameterTypes(), desc_s.getParameterTypes())) { 8.201 + if (!desc_s.getReturnType().hasTag(VOID)) { 8.202 + //perform structural comparison 8.203 + Type ret_t = desc_t.getReturnType(); 8.204 + Type ret_s = desc_s.getReturnType(); 8.205 + scanLambdaBody(tree, ret_t, ret_s); 8.206 + } else { 8.207 + return; 8.208 + } 8.209 + } else { 8.210 + result &= false; 8.211 + } 8.212 + } else { 8.213 + result &= MostSpecificCheckContext.super.compatible(t, s, warn); 8.214 + } 8.215 + } 8.216 + //where 8.217 + 8.218 + void scanLambdaBody(JCLambda lambda, final Type t, final Type s) { 8.219 + if (lambda.getBodyKind() == JCTree.JCLambda.BodyKind.EXPRESSION) { 8.220 + result &= MostSpecificCheckContext.this.mostSpecific(t, s, lambda.body, warn); 8.221 + } else { 8.222 + DeferredAttr.LambdaReturnScanner lambdaScanner = 8.223 + new DeferredAttr.LambdaReturnScanner() { 8.224 + @Override 8.225 + public void visitReturn(JCReturn tree) { 8.226 + if (tree.expr != null) { 8.227 + result &= MostSpecificCheckContext.this.mostSpecific(t, s, tree.expr, warn); 8.228 + } 8.229 + } 8.230 + }; 8.231 + lambdaScanner.scan(lambda.body); 8.232 + } 8.233 + } 8.234 + } 8.235 + } 8.236 + } 8.237 + 8.238 public static class InapplicableMethodException extends RuntimeException { 8.239 private static final long serialVersionUID = 0; 8.240 8.241 @@ -1142,151 +1352,30 @@ 8.242 } 8.243 //where 8.244 private boolean signatureMoreSpecific(List<Type> actuals, Env<AttrContext> env, Type site, Symbol m1, Symbol m2, boolean allowBoxing, boolean useVarargs) { 8.245 - Symbol m12 = adjustVarargs(m1, m2, useVarargs); 8.246 - Symbol m22 = adjustVarargs(m2, m1, useVarargs); 8.247 - Type mtype1 = types.memberType(site, m12); 8.248 - Type mtype2 = types.memberType(site, m22); 8.249 - 8.250 - //check if invocation is more specific 8.251 - if (invocationMoreSpecific(env, site, m22, mtype1.getParameterTypes(), allowBoxing, useVarargs)) { 8.252 - return true; 8.253 + noteWarner.clear(); 8.254 + int maxLength = Math.max( 8.255 + Math.max(m1.type.getParameterTypes().length(), actuals.length()), 8.256 + m2.type.getParameterTypes().length()); 8.257 + Type mst = instantiate(env, site, m2, null, 8.258 + adjustArgs(types.lowerBounds(types.memberType(site, m1).getParameterTypes()), m1, maxLength, useVarargs), null, 8.259 + allowBoxing, useVarargs, new MostSpecificCheck(!allowBoxing, actuals), noteWarner); 8.260 + return mst != null && 8.261 + !noteWarner.hasLint(Lint.LintCategory.UNCHECKED); 8.262 + } 8.263 + private List<Type> adjustArgs(List<Type> args, Symbol msym, int length, boolean allowVarargs) { 8.264 + if ((msym.flags() & VARARGS) != 0 && allowVarargs) { 8.265 + Type varargsElem = types.elemtype(args.last()); 8.266 + if (varargsElem == null) { 8.267 + Assert.error("Bad varargs = " + args.last() + " " + msym); 8.268 + } 8.269 + List<Type> newArgs = args.reverse().tail.prepend(varargsElem).reverse(); 8.270 + while (newArgs.length() < length) { 8.271 + newArgs = newArgs.append(newArgs.last()); 8.272 + } 8.273 + return newArgs; 8.274 + } else { 8.275 + return args; 8.276 } 8.277 - 8.278 - //perform structural check 8.279 - 8.280 - List<Type> formals1 = mtype1.getParameterTypes(); 8.281 - Type lastFormal1 = formals1.last(); 8.282 - List<Type> formals2 = mtype2.getParameterTypes(); 8.283 - Type lastFormal2 = formals2.last(); 8.284 - ListBuffer<Type> newFormals = ListBuffer.lb(); 8.285 - 8.286 - boolean hasStructuralPoly = false; 8.287 - for (Type actual : actuals) { 8.288 - //perform formal argument adaptation in case actuals > formals (varargs) 8.289 - Type f1 = formals1.isEmpty() ? 8.290 - lastFormal1 : formals1.head; 8.291 - Type f2 = formals2.isEmpty() ? 8.292 - lastFormal2 : formals2.head; 8.293 - 8.294 - //is this a structural actual argument? 8.295 - boolean isStructuralPoly = actual.hasTag(DEFERRED) && 8.296 - (((DeferredType)actual).tree.hasTag(LAMBDA) || 8.297 - ((DeferredType)actual).tree.hasTag(REFERENCE)); 8.298 - 8.299 - Type newFormal = f1; 8.300 - 8.301 - if (isStructuralPoly) { 8.302 - //for structural arguments only - check that corresponding formals 8.303 - //are related - if so replace formal with <null> 8.304 - hasStructuralPoly = true; 8.305 - DeferredType dt = (DeferredType)actual; 8.306 - Type t1 = deferredAttr.new DeferredTypeMap(AttrMode.SPECULATIVE, m1, currentResolutionContext.step).apply(dt); 8.307 - Type t2 = deferredAttr.new DeferredTypeMap(AttrMode.SPECULATIVE, m2, currentResolutionContext.step).apply(dt); 8.308 - if (t1.isErroneous() || t2.isErroneous() || !isStructuralSubtype(t1, t2)) { 8.309 - //not structural subtypes - simply fail 8.310 - return false; 8.311 - } else { 8.312 - newFormal = syms.botType; 8.313 - } 8.314 - } 8.315 - 8.316 - newFormals.append(newFormal); 8.317 - if (newFormals.length() > mtype2.getParameterTypes().length()) { 8.318 - //expand m2's type so as to fit the new formal arity (varargs) 8.319 - m22.type = types.createMethodTypeWithParameters(m22.type, m22.type.getParameterTypes().append(f2)); 8.320 - } 8.321 - 8.322 - formals1 = formals1.isEmpty() ? formals1 : formals1.tail; 8.323 - formals2 = formals2.isEmpty() ? formals2 : formals2.tail; 8.324 - } 8.325 - 8.326 - if (!hasStructuralPoly) { 8.327 - //if no structural actual was found, we're done 8.328 - return false; 8.329 - } 8.330 - //perform additional adaptation if actuals < formals (varargs) 8.331 - for (Type t : formals1) { 8.332 - newFormals.append(t); 8.333 - } 8.334 - //check if invocation (with tweaked args) is more specific 8.335 - return invocationMoreSpecific(env, site, m22, newFormals.toList(), allowBoxing, useVarargs); 8.336 - } 8.337 - //where 8.338 - private boolean invocationMoreSpecific(Env<AttrContext> env, Type site, Symbol m2, List<Type> argtypes1, boolean allowBoxing, boolean useVarargs) { 8.339 - MethodResolutionContext prevContext = currentResolutionContext; 8.340 - try { 8.341 - currentResolutionContext = new MethodResolutionContext(); 8.342 - currentResolutionContext.step = allowBoxing ? BOX : BASIC; 8.343 - noteWarner.clear(); 8.344 - Type mst = instantiate(env, site, m2, null, 8.345 - types.lowerBounds(argtypes1), null, 8.346 - allowBoxing, false, resolveMethodCheck, noteWarner); 8.347 - return mst != null && 8.348 - !noteWarner.hasLint(Lint.LintCategory.UNCHECKED); 8.349 - } finally { 8.350 - currentResolutionContext = prevContext; 8.351 - } 8.352 - } 8.353 - //where 8.354 - private Symbol adjustVarargs(Symbol to, Symbol from, boolean useVarargs) { 8.355 - List<Type> fromArgs = from.type.getParameterTypes(); 8.356 - List<Type> toArgs = to.type.getParameterTypes(); 8.357 - if (useVarargs && 8.358 - (from.flags() & VARARGS) != 0 && 8.359 - (to.flags() & VARARGS) != 0) { 8.360 - Type varargsTypeFrom = fromArgs.last(); 8.361 - Type varargsTypeTo = toArgs.last(); 8.362 - ListBuffer<Type> args = ListBuffer.lb(); 8.363 - if (toArgs.length() < fromArgs.length()) { 8.364 - //if we are checking a varargs method 'from' against another varargs 8.365 - //method 'to' (where arity of 'to' < arity of 'from') then expand signature 8.366 - //of 'to' to 'fit' arity of 'from' (this means adding fake formals to 'to' 8.367 - //until 'to' signature has the same arity as 'from') 8.368 - while (fromArgs.head != varargsTypeFrom) { 8.369 - args.append(toArgs.head == varargsTypeTo ? types.elemtype(varargsTypeTo) : toArgs.head); 8.370 - fromArgs = fromArgs.tail; 8.371 - toArgs = toArgs.head == varargsTypeTo ? 8.372 - toArgs : 8.373 - toArgs.tail; 8.374 - } 8.375 - } else { 8.376 - //formal argument list is same as original list where last 8.377 - //argument (array type) is removed 8.378 - args.appendList(toArgs.reverse().tail.reverse()); 8.379 - } 8.380 - //append varargs element type as last synthetic formal 8.381 - args.append(types.elemtype(varargsTypeTo)); 8.382 - Type mtype = types.createMethodTypeWithParameters(to.type, args.toList()); 8.383 - return new MethodSymbol(to.flags_field & ~VARARGS, to.name, mtype, to.owner); 8.384 - } else { 8.385 - return to; 8.386 - } 8.387 - } 8.388 - //where 8.389 - boolean isStructuralSubtype(Type s, Type t) { 8.390 - 8.391 - Type ret_s = types.findDescriptorType(s).getReturnType(); 8.392 - Type ret_t = types.findDescriptorType(t).getReturnType(); 8.393 - 8.394 - //covariant most specific check for function descriptor return type 8.395 - if (!types.isSubtype(ret_s, ret_t)) { 8.396 - return false; 8.397 - } 8.398 - 8.399 - List<Type> args_s = types.findDescriptorType(s).getParameterTypes(); 8.400 - List<Type> args_t = types.findDescriptorType(t).getParameterTypes(); 8.401 - 8.402 - //arity must be identical 8.403 - if (args_s.length() != args_t.length()) { 8.404 - return false; 8.405 - } 8.406 - 8.407 - //invariant most specific check for function descriptor parameter types 8.408 - if (!types.isSameTypes(args_t, args_s)) { 8.409 - return false; 8.410 - } 8.411 - 8.412 - return true; 8.413 } 8.414 //where 8.415 Type mostSpecificReturnType(Type mt1, Type mt2) {
9.1 --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Mon Jan 21 11:16:28 2013 -0800 9.2 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Mon Jan 21 20:13:56 2013 +0000 9.3 @@ -549,9 +549,6 @@ 9.4 currentMethod = null; 9.5 tree.params = translate(tree.params); 9.6 tree.body = translate(tree.body, null); 9.7 - //save non-erased target 9.8 - tree.targetType = tree.type; 9.9 - Assert.check(!tree.targetType.isCompound(), "Intersection-type targets not supported yet!"); 9.10 tree.type = erasure(tree.type); 9.11 result = tree; 9.12 } 9.13 @@ -785,9 +782,6 @@ 9.14 9.15 public void visitReference(JCMemberReference tree) { 9.16 tree.expr = translate(tree.expr, null); 9.17 - //save non-erased target 9.18 - tree.targetType = tree.type; 9.19 - Assert.check(!tree.targetType.isCompound(), "Intersection-type targets not supported yet!"); 9.20 tree.type = erasure(tree.type); 9.21 result = tree; 9.22 }
10.1 --- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java Mon Jan 21 11:16:28 2013 -0800 10.2 +++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java Mon Jan 21 20:13:56 2013 +0000 10.3 @@ -607,6 +607,42 @@ 10.4 } 10.5 10.6 /** 10.7 + * Common supertype for all poly expression trees (lambda, method references, 10.8 + * conditionals, method and constructor calls) 10.9 + */ 10.10 + public static abstract class JCPolyExpression extends JCExpression { 10.11 + 10.12 + /** 10.13 + * A poly expression can only be truly 'poly' in certain contexts 10.14 + */ 10.15 + public enum PolyKind { 10.16 + /** poly expression to be treated as a standalone expression */ 10.17 + STANDALONE, 10.18 + /** true poly expression */ 10.19 + POLY; 10.20 + } 10.21 + 10.22 + /** is this poly expression a 'true' poly expression? */ 10.23 + public PolyKind polyKind; 10.24 + } 10.25 + 10.26 + /** 10.27 + * Common supertype for all functional expression trees (lambda and method references) 10.28 + */ 10.29 + public static abstract class JCFunctionalExpression extends JCPolyExpression { 10.30 + 10.31 + public JCFunctionalExpression() { 10.32 + //a functional expression is always a 'true' poly 10.33 + polyKind = PolyKind.POLY; 10.34 + } 10.35 + 10.36 + /** target descriptor inferred for this functional expression. */ 10.37 + public Type descriptorType; 10.38 + /** list of target types inferred for this functional expression. */ 10.39 + public List<TypeSymbol> targets; 10.40 + } 10.41 + 10.42 + /** 10.43 * A class definition. 10.44 */ 10.45 public static class JCClassDecl extends JCStatement implements ClassTree { 10.46 @@ -1147,7 +1183,7 @@ 10.47 /** 10.48 * A ( ) ? ( ) : ( ) conditional expression 10.49 */ 10.50 - public static class JCConditional extends JCExpression implements ConditionalExpressionTree { 10.51 + public static class JCConditional extends JCPolyExpression implements ConditionalExpressionTree { 10.52 public JCExpression cond; 10.53 public JCExpression truepart; 10.54 public JCExpression falsepart; 10.55 @@ -1373,7 +1409,7 @@ 10.56 /** 10.57 * A method invocation 10.58 */ 10.59 - public static class JCMethodInvocation extends JCExpression implements MethodInvocationTree { 10.60 + public static class JCMethodInvocation extends JCPolyExpression implements MethodInvocationTree { 10.61 public List<JCExpression> typeargs; 10.62 public JCExpression meth; 10.63 public List<JCExpression> args; 10.64 @@ -1416,7 +1452,7 @@ 10.65 /** 10.66 * A new(...) operation. 10.67 */ 10.68 - public static class JCNewClass extends JCExpression implements NewClassTree { 10.69 + public static class JCNewClass extends JCPolyExpression implements NewClassTree { 10.70 public JCExpression encl; 10.71 public List<JCExpression> typeargs; 10.72 public JCExpression clazz; 10.73 @@ -1502,18 +1538,29 @@ 10.74 /** 10.75 * A lambda expression. 10.76 */ 10.77 - public static class JCLambda extends JCExpression implements LambdaExpressionTree { 10.78 + public static class JCLambda extends JCFunctionalExpression implements LambdaExpressionTree { 10.79 + 10.80 + public enum ParameterKind { 10.81 + IMPLICIT, 10.82 + EXPLICIT; 10.83 + } 10.84 10.85 public List<JCVariableDecl> params; 10.86 public JCTree body; 10.87 - public Type targetType; 10.88 public boolean canCompleteNormally = true; 10.89 public List<Type> inferredThrownTypes; 10.90 + public ParameterKind paramKind; 10.91 10.92 public JCLambda(List<JCVariableDecl> params, 10.93 JCTree body) { 10.94 this.params = params; 10.95 this.body = body; 10.96 + if (params.isEmpty() || 10.97 + params.head.vartype != null) { 10.98 + paramKind = ParameterKind.EXPLICIT; 10.99 + } else { 10.100 + paramKind = ParameterKind.IMPLICIT; 10.101 + } 10.102 } 10.103 @Override 10.104 public Tag getTag() { 10.105 @@ -1812,15 +1859,15 @@ 10.106 /** 10.107 * Selects a member expression. 10.108 */ 10.109 - public static class JCMemberReference extends JCExpression implements MemberReferenceTree { 10.110 + public static class JCMemberReference extends JCFunctionalExpression implements MemberReferenceTree { 10.111 public ReferenceMode mode; 10.112 public ReferenceKind kind; 10.113 public Name name; 10.114 public JCExpression expr; 10.115 public List<JCExpression> typeargs; 10.116 - public Type targetType; 10.117 public Symbol sym; 10.118 public Type varargsElement; 10.119 + public PolyKind refPolyKind; 10.120 10.121 /** 10.122 * Javac-dependent classification for member references, based
11.1 --- a/src/share/classes/com/sun/tools/javac/tree/Pretty.java Mon Jan 21 11:16:28 2013 -0800 11.2 +++ b/src/share/classes/com/sun/tools/javac/tree/Pretty.java Mon Jan 21 20:13:56 2013 +0000 11.3 @@ -946,7 +946,7 @@ 11.4 public void visitLambda(JCLambda tree) { 11.5 try { 11.6 print("("); 11.7 - if (TreeInfo.isExplicitLambda(tree)) { 11.8 + if (tree.paramKind == JCLambda.ParameterKind.EXPLICIT) { 11.9 printExprs(tree.params); 11.10 } else { 11.11 String sep = "";
12.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Mon Jan 21 11:16:28 2013 -0800 12.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Mon Jan 21 20:13:56 2013 +0000 12.3 @@ -32,6 +32,7 @@ 12.4 import com.sun.tools.javac.comp.AttrContext; 12.5 import com.sun.tools.javac.comp.Env; 12.6 import com.sun.tools.javac.tree.JCTree.*; 12.7 +import com.sun.tools.javac.tree.JCTree.JCPolyExpression.*; 12.8 import com.sun.tools.javac.util.*; 12.9 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 12.10 import static com.sun.tools.javac.code.Flags.*; 12.11 @@ -264,9 +265,38 @@ 12.12 } 12.13 } 12.14 12.15 - public static boolean isExplicitLambda(JCLambda lambda) { 12.16 - return lambda.params.isEmpty() || 12.17 - lambda.params.head.vartype != null; 12.18 + /** set 'polyKind' on given tree */ 12.19 + public static void setPolyKind(JCTree tree, PolyKind pkind) { 12.20 + switch (tree.getTag()) { 12.21 + case APPLY: 12.22 + ((JCMethodInvocation)tree).polyKind = pkind; 12.23 + break; 12.24 + case NEWCLASS: 12.25 + ((JCNewClass)tree).polyKind = pkind; 12.26 + break; 12.27 + case REFERENCE: 12.28 + ((JCMemberReference)tree).refPolyKind = pkind; 12.29 + break; 12.30 + default: 12.31 + throw new AssertionError("Unexpected tree: " + tree); 12.32 + } 12.33 + } 12.34 + 12.35 + /** set 'varargsElement' on given tree */ 12.36 + public static void setVarargsElement(JCTree tree, Type varargsElement) { 12.37 + switch (tree.getTag()) { 12.38 + case APPLY: 12.39 + ((JCMethodInvocation)tree).varargsElement = varargsElement; 12.40 + break; 12.41 + case NEWCLASS: 12.42 + ((JCNewClass)tree).varargsElement = varargsElement; 12.43 + break; 12.44 + case REFERENCE: 12.45 + ((JCMemberReference)tree).varargsElement = varargsElement; 12.46 + break; 12.47 + default: 12.48 + throw new AssertionError("Unexpected tree: " + tree); 12.49 + } 12.50 } 12.51 12.52 /** Return true if the tree corresponds to an expression statement */
13.1 --- a/test/tools/javac/Diagnostics/6722234/T6722234d_1.out Mon Jan 21 11:16:28 2013 -0800 13.2 +++ b/test/tools/javac/Diagnostics/6722234/T6722234d_1.out Mon Jan 21 20:13:56 2013 +0000 13.3 @@ -1,3 +1,3 @@ 13.4 -T6722234d.java:18:20: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.intersection.type: 1, T6722234d.A) 13.5 +T6722234d.java:18:20: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: compiler.misc.intersection.type: 1, T6722234d.A,java.lang.Object) 13.6 - compiler.misc.where.description.intersection: compiler.misc.intersection.type: 1,{(compiler.misc.where.intersection: compiler.misc.intersection.type: 1, java.lang.Object,T6722234d.I1,T6722234d.I2)} 13.7 1 error
14.1 --- a/test/tools/javac/Diagnostics/6722234/T6722234d_2.out Mon Jan 21 11:16:28 2013 -0800 14.2 +++ b/test/tools/javac/Diagnostics/6722234/T6722234d_2.out Mon Jan 21 20:13:56 2013 +0000 14.3 @@ -1,3 +1,3 @@ 14.4 -T6722234d.java:18:20: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.intersection.type: 1, T6722234d.A) 14.5 +T6722234d.java:18:20: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: compiler.misc.intersection.type: 1, T6722234d.A,Object) 14.6 - compiler.misc.where.description.intersection: compiler.misc.intersection.type: 1,{(compiler.misc.where.intersection: compiler.misc.intersection.type: 1, Object,I1,I2)} 14.7 1 error
15.1 --- a/test/tools/javac/diags/examples.not-yet.txt Mon Jan 21 11:16:28 2013 -0800 15.2 +++ b/test/tools/javac/diags/examples.not-yet.txt Mon Jan 21 20:13:56 2013 +0000 15.3 @@ -59,6 +59,7 @@ 15.4 compiler.misc.fatal.err.cant.close # JavaCompiler 15.5 compiler.misc.file.does.not.contain.package 15.6 compiler.misc.illegal.start.of.class.file 15.7 +compiler.misc.inferred.do.not.conform.to.lower.bounds # cannot happen? 15.8 compiler.misc.kindname.annotation 15.9 compiler.misc.kindname.enum 15.10 compiler.misc.kindname.package 15.11 @@ -68,6 +69,7 @@ 15.12 compiler.misc.kindname.value 15.13 compiler.misc.incompatible.eq.lower.bounds # cannot happen? 15.14 compiler.misc.no.unique.minimal.instance.exists 15.15 +compiler.misc.no.unique.maximal.instance.exists # cannot happen? 15.16 compiler.misc.resume.abort # prompt for a response 15.17 compiler.misc.source.unavailable # DiagnosticSource 15.18 compiler.misc.token.bad-symbol
16.1 --- a/test/tools/javac/diags/examples/CyclicInference.java Mon Jan 21 11:16:28 2013 -0800 16.2 +++ b/test/tools/javac/diags/examples/CyclicInference.java Mon Jan 21 20:13:56 2013 +0000 16.3 @@ -21,7 +21,7 @@ 16.4 * questions. 16.5 */ 16.6 16.7 -// key: compiler.err.cant.apply.symbol 16.8 +// key: compiler.err.prob.found.req 16.9 // key: compiler.misc.cyclic.inference 16.10 16.11 class CyclicInference {
17.1 --- a/test/tools/javac/diags/examples/InferredDoNotConformToLower.java Mon Jan 21 11:16:28 2013 -0800 17.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 17.3 @@ -1,32 +0,0 @@ 17.4 -/* 17.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 17.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 17.7 - * 17.8 - * This code is free software; you can redistribute it and/or modify it 17.9 - * under the terms of the GNU General Public License version 2 only, as 17.10 - * published by the Free Software Foundation. 17.11 - * 17.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 17.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17.15 - * version 2 for more details (a copy is included in the LICENSE file that 17.16 - * accompanied this code). 17.17 - * 17.18 - * You should have received a copy of the GNU General Public License version 17.19 - * 2 along with this work; if not, write to the Free Software Foundation, 17.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17.21 - * 17.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 17.23 - * or visit www.oracle.com if you need additional information or have any 17.24 - * questions. 17.25 - */ 17.26 - 17.27 -// key: compiler.err.prob.found.req 17.28 -// key: compiler.misc.inferred.do.not.conform.to.lower.bounds 17.29 - 17.30 -import java.util.*; 17.31 - 17.32 -class InferredDoNotConformToLower { 17.33 - <X extends Number> List<X> m() { return null; } 17.34 - { List<? super String> lss = this.m(); } 17.35 -}
18.1 --- a/test/tools/javac/diags/examples/NoUniqueMaximalInstance.java Mon Jan 21 11:16:28 2013 -0800 18.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 18.3 @@ -1,31 +0,0 @@ 18.4 -/* 18.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 18.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 18.7 - * 18.8 - * This code is free software; you can redistribute it and/or modify it 18.9 - * under the terms of the GNU General Public License version 2 only, as 18.10 - * published by the Free Software Foundation. 18.11 - * 18.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 18.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 18.15 - * version 2 for more details (a copy is included in the LICENSE file that 18.16 - * accompanied this code). 18.17 - * 18.18 - * You should have received a copy of the GNU General Public License version 18.19 - * 2 along with this work; if not, write to the Free Software Foundation, 18.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18.21 - * 18.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 18.23 - * or visit www.oracle.com if you need additional information or have any 18.24 - * questions. 18.25 - */ 18.26 - 18.27 -// key: compiler.err.prob.found.req 18.28 -// key: compiler.misc.no.unique.maximal.instance.exists 18.29 - 18.30 -class NoUniqueMaximalInstance { 18.31 - <Z extends Integer> Z m() { return null; } 18.32 - 18.33 - { String s = m(); } 18.34 -}
19.1 --- a/test/tools/javac/diags/examples/WhereIntersection.java Mon Jan 21 11:16:28 2013 -0800 19.2 +++ b/test/tools/javac/diags/examples/WhereIntersection.java Mon Jan 21 20:13:56 2013 +0000 19.3 @@ -25,7 +25,7 @@ 19.4 // key: compiler.misc.where.description.intersection 19.5 // key: compiler.misc.intersection.type 19.6 // key: compiler.err.prob.found.req 19.7 -// key: compiler.misc.inconvertible.types 19.8 +// key: compiler.misc.inferred.do.not.conform.to.upper.bounds 19.9 // options: -XDdiags=where 19.10 // run: simple 19.11
20.1 --- a/test/tools/javac/generics/diamond/T6939780.out Mon Jan 21 11:16:28 2013 -0800 20.2 +++ b/test/tools/javac/generics/diamond/T6939780.out Mon Jan 21 20:13:56 2013 +0000 20.3 @@ -1,3 +1,4 @@ 20.4 +T6939780.java:18:33: compiler.warn.diamond.redundant.args: Foo<java.lang.Number>, Foo<java.lang.Number> 20.5 T6939780.java:19:28: compiler.warn.diamond.redundant.args: Foo<java.lang.Number>, Foo<java.lang.Number> 20.6 T6939780.java:20:28: compiler.warn.diamond.redundant.args.1: Foo<java.lang.Integer>, Foo<java.lang.Number> 20.7 -2 warnings 20.8 +3 warnings
21.1 --- a/test/tools/javac/generics/diamond/neg/Neg05.out Mon Jan 21 11:16:28 2013 -0800 21.2 +++ b/test/tools/javac/generics/diamond/neg/Neg05.out Mon Jan 21 20:13:56 2013 +0000 21.3 @@ -1,25 +1,25 @@ 21.4 Neg05.java:19:48: compiler.err.improperly.formed.type.inner.raw.param 21.5 -Neg05.java:19:35: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: Neg05.Foo<java.lang.String>, Neg05<?>.Foo<java.lang.String>) 21.6 Neg05.java:20:58: compiler.err.improperly.formed.type.inner.raw.param 21.7 -Neg05.java:20:45: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: Neg05.Foo<java.lang.String>, Neg05<?>.Foo<? extends java.lang.String>) 21.8 Neg05.java:21:43: compiler.err.improperly.formed.type.inner.raw.param 21.9 -Neg05.java:21:30: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: Neg05.Foo<java.lang.String>, Neg05<?>.Foo<?>) 21.10 Neg05.java:22:56: compiler.err.improperly.formed.type.inner.raw.param 21.11 -Neg05.java:22:43: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: Neg05.Foo<java.lang.String>, Neg05<?>.Foo<? super java.lang.String>) 21.12 Neg05.java:24:48: compiler.err.improperly.formed.type.inner.raw.param 21.13 -Neg05.java:24:35: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: Neg05.Foo<java.lang.String>, Neg05<?>.Foo<java.lang.String>) 21.14 Neg05.java:25:58: compiler.err.improperly.formed.type.inner.raw.param 21.15 -Neg05.java:25:45: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: Neg05.Foo<java.lang.String>, Neg05<?>.Foo<? extends java.lang.String>) 21.16 Neg05.java:26:43: compiler.err.improperly.formed.type.inner.raw.param 21.17 -Neg05.java:26:30: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: Neg05.Foo<java.lang.String>, Neg05<?>.Foo<?>) 21.18 Neg05.java:27:56: compiler.err.improperly.formed.type.inner.raw.param 21.19 -Neg05.java:27:43: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: Neg05.Foo<java.lang.String>, Neg05<?>.Foo<? super java.lang.String>) 21.20 Neg05.java:31:37: compiler.err.improperly.formed.type.inner.raw.param 21.21 +Neg05.java:31:44: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V, Neg05.Foo<V>, Neg05<?>.Foo<java.lang.String>)) 21.22 Neg05.java:32:47: compiler.err.improperly.formed.type.inner.raw.param 21.23 +Neg05.java:32:54: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V, Neg05.Foo<V>, Neg05<?>.Foo<? extends java.lang.String>)) 21.24 Neg05.java:33:32: compiler.err.improperly.formed.type.inner.raw.param 21.25 +Neg05.java:33:39: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V, Neg05.Foo<V>, Neg05<?>.Foo<?>)) 21.26 Neg05.java:34:45: compiler.err.improperly.formed.type.inner.raw.param 21.27 +Neg05.java:34:52: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V, Neg05.Foo<V>, Neg05<?>.Foo<? super java.lang.String>)) 21.28 Neg05.java:36:37: compiler.err.improperly.formed.type.inner.raw.param 21.29 +Neg05.java:36:44: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V,Z, Neg05.Foo<V>, Neg05<?>.Foo<java.lang.String>)) 21.30 Neg05.java:37:47: compiler.err.improperly.formed.type.inner.raw.param 21.31 +Neg05.java:37:54: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V,Z, Neg05.Foo<V>, Neg05<?>.Foo<? extends java.lang.String>)) 21.32 Neg05.java:38:32: compiler.err.improperly.formed.type.inner.raw.param 21.33 +Neg05.java:38:39: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V,Z, Neg05.Foo<V>, Neg05<?>.Foo<?>)) 21.34 Neg05.java:39:45: compiler.err.improperly.formed.type.inner.raw.param 21.35 +Neg05.java:39:52: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg05.Foo), (compiler.misc.infer.no.conforming.instance.exists: V,Z, Neg05.Foo<V>, Neg05<?>.Foo<? super java.lang.String>)) 21.36 24 errors
22.1 --- a/test/tools/javac/generics/diamond/neg/Neg10.java Mon Jan 21 11:16:28 2013 -0800 22.2 +++ b/test/tools/javac/generics/diamond/neg/Neg10.java Mon Jan 21 20:13:56 2013 +0000 22.3 @@ -4,7 +4,8 @@ 22.4 * 22.5 * @summary Check that 'complex' diamond can infer type that is too specific 22.6 * @author mcimadamore 22.7 - * @compile/fail/ref=Neg10.out Neg10.java -XDrawDiagnostics 22.8 + * @compile/fail/ref=Neg10.out -source 7 -Xlint:-options Neg10.java -XDrawDiagnostics 22.9 + * @compile Neg10.java -XDrawDiagnostics 22.10 * 22.11 */ 22.12
23.1 --- a/test/tools/javac/generics/diamond/neg/Neg10.out Mon Jan 21 11:16:28 2013 -0800 23.2 +++ b/test/tools/javac/generics/diamond/neg/Neg10.out Mon Jan 21 20:13:56 2013 +0000 23.3 @@ -1,2 +1,2 @@ 23.4 -Neg10.java:16:22: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: Neg10.Foo<java.lang.Integer>, Neg10.Foo<java.lang.Number>) 23.5 +Neg10.java:17:22: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: Neg10.Foo<java.lang.Integer>, Neg10.Foo<java.lang.Number>) 23.6 1 error
24.1 --- a/test/tools/javac/generics/inference/6315770/T6315770.out Mon Jan 21 11:16:28 2013 -0800 24.2 +++ b/test/tools/javac/generics/inference/6315770/T6315770.out Mon Jan 21 20:13:56 2013 +0000 24.3 @@ -1,3 +1,3 @@ 24.4 -T6315770.java:16:42: compiler.err.prob.found.req: (compiler.misc.no.unique.maximal.instance.exists: T, java.lang.String,java.lang.Integer,java.lang.Runnable) 24.5 -T6315770.java:17:40: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.lower.bounds: java.lang.Integer&java.lang.Runnable, java.lang.String) 24.6 +T6315770.java:16:42: compiler.err.prob.found.req: (compiler.misc.incompatible.upper.bounds: T, java.lang.String,java.lang.Integer,java.lang.Runnable) 24.7 +T6315770.java:17:40: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.String, java.lang.Integer,java.lang.Runnable) 24.8 2 errors
25.1 --- a/test/tools/javac/generics/inference/6638712/T6638712b.out Mon Jan 21 11:16:28 2013 -0800 25.2 +++ b/test/tools/javac/generics/inference/6638712/T6638712b.out Mon Jan 21 20:13:56 2013 +0000 25.3 @@ -1,2 +1,2 @@ 25.4 -T6638712b.java:14:21: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, java.lang.String,java.lang.Object) 25.5 +T6638712b.java:14:21: compiler.err.prob.found.req: (compiler.misc.incompatible.eq.upper.bounds: T, java.lang.Integer, java.lang.String,java.lang.Object) 25.6 1 error
26.1 --- a/test/tools/javac/generics/inference/6650759/T6650759m.out Mon Jan 21 11:16:28 2013 -0800 26.2 +++ b/test/tools/javac/generics/inference/6650759/T6650759m.out Mon Jan 21 20:13:56 2013 +0000 26.3 @@ -1,2 +1,2 @@ 26.4 -T6650759m.java:43:36: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.lower.bounds: java.lang.Integer, java.lang.String) 26.5 +T6650759m.java:43:36: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.String, java.lang.Integer,java.lang.Object) 26.6 1 error
27.1 --- a/test/tools/javac/lambda/MethodReference25.java Mon Jan 21 11:16:28 2013 -0800 27.2 +++ b/test/tools/javac/lambda/MethodReference25.java Mon Jan 21 20:13:56 2013 +0000 27.3 @@ -25,21 +25,13 @@ 27.4 * @test 27.5 * @bug 8003280 27.6 * @summary Add lambda tests 27.7 - * check that non-boxing method references conversion has the precedence 27.8 - * @run main MethodReference25 27.9 + * check that non-boxing method references is not preferred over boxing one 27.10 + * @compile/fail/ref=MethodReference25.out -XDrawDiagnostics MethodReference25.java 27.11 */ 27.12 27.13 -public class MethodReference25 { 27.14 +class MethodReference25 { 27.15 27.16 - static void assertTrue(boolean cond) { 27.17 - assertionCount++; 27.18 - if (!cond) 27.19 - throw new AssertionError(); 27.20 - } 27.21 - 27.22 - static int assertionCount = 0; 27.23 - 27.24 - static void m(Integer i) { assertTrue(true); } 27.25 + static void m(Integer i) { } 27.26 27.27 interface SAM1 { 27.28 void m(int x); 27.29 @@ -49,11 +41,10 @@ 27.30 void m(Integer x); 27.31 } 27.32 27.33 - static void call(int i, SAM1 s) { s.m(i); assertTrue(false); } 27.34 + static void call(int i, SAM1 s) { s.m(i); } 27.35 static void call(int i, SAM2 s) { s.m(i); } 27.36 27.37 public static void main(String[] args) { 27.38 - call(1, MethodReference25::m); //resolves to call(int, SAM2) 27.39 - assertTrue(assertionCount == 1); 27.40 + call(1, MethodReference25::m); //ambiguous 27.41 } 27.42 }
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 28.2 +++ b/test/tools/javac/lambda/MethodReference25.out Mon Jan 21 20:13:56 2013 +0000 28.3 @@ -0,0 +1,2 @@ 28.4 +MethodReference25.java:48:9: compiler.err.ref.ambiguous: call, kindname.method, call(int,MethodReference25.SAM1), MethodReference25, kindname.method, call(int,MethodReference25.SAM2), MethodReference25 28.5 +1 error
29.1 --- a/test/tools/javac/lambda/MethodReference26.java Mon Jan 21 11:16:28 2013 -0800 29.2 +++ b/test/tools/javac/lambda/MethodReference26.java Mon Jan 21 20:13:56 2013 +0000 29.3 @@ -1,9 +1,30 @@ 29.4 /* 29.5 - * @test /nodynamiccopyright/ 29.6 - * @bug 8003280 29.7 - * @summary Add lambda tests 29.8 - * check strict method conversion does not allow loose method reference conversion 29.9 - * @compile/fail/ref=MethodReference26.out -XDrawDiagnostics MethodReference26.java 29.10 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 29.11 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 29.12 + * 29.13 + * This code is free software; you can redistribute it and/or modify it 29.14 + * under the terms of the GNU General Public License version 2 only, as 29.15 + * published by the Free Software Foundation. 29.16 + * 29.17 + * This code is distributed in the hope that it will be useful, but WITHOUT 29.18 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 29.19 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 29.20 + * version 2 for more details (a copy is included in the LICENSE file that 29.21 + * accompanied this code). 29.22 + * 29.23 + * You should have received a copy of the GNU General Public License version 29.24 + * 2 along with this work; if not, write to the Free Software Foundation, 29.25 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 29.26 + * 29.27 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 29.28 + * or visit www.oracle.com if you need additional information or have any 29.29 + * questions. 29.30 + */ 29.31 + 29.32 +/* 29.33 + * @test 29.34 + * @summary check strict method conversion allows loose method reference conversion 29.35 + * @compile MethodReference26.java 29.36 */ 29.37 29.38 class MethodReference26 { 29.39 @@ -18,6 +39,6 @@ 29.40 static void call(Integer i, SAM s) { } 29.41 29.42 static void test() { 29.43 - call(1, MethodReference26::m); //ambiguous 29.44 + call(1, MethodReference26::m); //ok 29.45 } 29.46 }
30.1 --- a/test/tools/javac/lambda/MethodReference26.out Mon Jan 21 11:16:28 2013 -0800 30.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 30.3 @@ -1,2 +0,0 @@ 30.4 -MethodReference26.java:21:9: compiler.err.ref.ambiguous: call, kindname.method, call(int,MethodReference26.SAM), MethodReference26, kindname.method, call(java.lang.Integer,MethodReference26.SAM), MethodReference26 30.5 -1 error
31.1 --- a/test/tools/javac/lambda/MethodReference43.java Mon Jan 21 11:16:28 2013 -0800 31.2 +++ b/test/tools/javac/lambda/MethodReference43.java Mon Jan 21 20:13:56 2013 +0000 31.3 @@ -60,9 +60,9 @@ 31.4 31.5 31.6 static void m(SAM1 s) { assertTrue(false); } 31.7 - static void m(SAM2 s) { assertTrue(true); } 31.8 + static void m(SAM2 s) { assertTrue(false); } 31.9 static void m(SAM3 s) { assertTrue(false); } 31.10 - static void m(SAM4 s) { assertTrue(false); } 31.11 + static void m(SAM4 s) { assertTrue(true); } 31.12 31.13 public static void main(String[] args) { 31.14 m(Foo::new);
32.1 --- a/test/tools/javac/lambda/TargetType01.java Mon Jan 21 11:16:28 2013 -0800 32.2 +++ b/test/tools/javac/lambda/TargetType01.java Mon Jan 21 20:13:56 2013 +0000 32.3 @@ -27,7 +27,7 @@ 32.4 * @summary Add lambda tests 32.5 * check nested case of overload resolution and lambda parameter inference 32.6 * @author Maurizio Cimadamore 32.7 - * @compile TargetType01.java 32.8 + * @compile/fail/ref=TargetType01.out -XDrawDiagnostics TargetType01.java 32.9 */ 32.10 32.11 class TargetType01 { 32.12 @@ -43,7 +43,6 @@ 32.13 static String M(F_S_S f){ return null; } 32.14 32.15 static { 32.16 - //ambiguity here - the compiler does not try all the combinations! 32.17 - M(x1 -> { return M( x2 -> { return x1 + x2; });}); 32.18 + M(x1 -> { return M( x2 -> { return x1 + x2; });}); //ambiguous 32.19 } 32.20 }
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 33.2 +++ b/test/tools/javac/lambda/TargetType01.out Mon Jan 21 20:13:56 2013 +0000 33.3 @@ -0,0 +1,3 @@ 33.4 +TargetType01.java:46:9: compiler.err.ref.ambiguous: M, kindname.method, M(TargetType01.F_I_I), TargetType01, kindname.method, M(TargetType01.F_S_S), TargetType01 33.5 +TargetType01.java:46:26: compiler.err.ref.ambiguous: M, kindname.method, M(TargetType01.F_I_I), TargetType01, kindname.method, M(TargetType01.F_S_S), TargetType01 33.6 +2 errors
34.1 --- a/test/tools/javac/lambda/TargetType06.java Mon Jan 21 11:16:28 2013 -0800 34.2 +++ b/test/tools/javac/lambda/TargetType06.java Mon Jan 21 20:13:56 2013 +0000 34.3 @@ -4,7 +4,7 @@ 34.4 * @summary Add lambda tests 34.5 * check complex case of target typing 34.6 * @author Maurizio Cimadamore 34.7 - * @compile/fail/ref=TargetType06.out -XDrawDiagnostics TargetType06.java 34.8 + * @compile TargetType06.java 34.9 */ 34.10 34.11 import java.util.List;
35.1 --- a/test/tools/javac/lambda/TargetType06.out Mon Jan 21 11:16:28 2013 -0800 35.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 35.3 @@ -1,2 +0,0 @@ 35.4 -TargetType06.java:25:23: compiler.err.cant.apply.symbol: kindname.method, map, TargetType06.Function<B,B>, @510, kindname.class, TargetType06, (compiler.misc.cyclic.inference: B) 35.5 -1 error
36.1 --- a/test/tools/javac/lambda/TargetType10.out Mon Jan 21 11:16:28 2013 -0800 36.2 +++ b/test/tools/javac/lambda/TargetType10.out Mon Jan 21 20:13:56 2013 +0000 36.3 @@ -1,2 +1,2 @@ 36.4 -TargetType10.java:17:11: compiler.err.cant.apply.symbol: kindname.method, compose, TargetType10.Function<B,C>,TargetType10.Function<A,? extends B>, @500,@515, kindname.class, TargetType10.Test, (compiler.misc.cyclic.inference: B,A) 36.5 +TargetType10.java:17:18: compiler.err.prob.found.req: (compiler.misc.cyclic.inference: B,A) 36.6 1 error
37.1 --- a/test/tools/javac/lambda/TargetType11.java Mon Jan 21 11:16:28 2013 -0800 37.2 +++ b/test/tools/javac/lambda/TargetType11.java Mon Jan 21 20:13:56 2013 +0000 37.3 @@ -4,7 +4,7 @@ 37.4 * @summary Add lambda tests 37.5 * check that wildcards in the target method of a lambda conversion is handled correctly 37.6 * @author Maurizio Cimadamore 37.7 - * @compile/fail/ref=TargetType11.out -Xlint:unchecked -XDrawDiagnostics TargetType11.java 37.8 + * @compile TargetType11.java 37.9 */ 37.10 37.11 class TargetType11 {
38.1 --- a/test/tools/javac/lambda/TargetType11.out Mon Jan 21 11:16:28 2013 -0800 38.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 38.3 @@ -1,4 +0,0 @@ 38.4 -TargetType11.java:16:61: compiler.warn.unchecked.varargs.non.reifiable.type: TargetType11.Predicate<? super T> 38.5 -TargetType11.java:20:32: compiler.err.cant.apply.symbol: kindname.method, and, TargetType11.Predicate<? super T>[], @706,@718, kindname.class, TargetType11.Test, (compiler.misc.cyclic.inference: T) 38.6 -1 error 38.7 -1 warning
39.1 --- a/test/tools/javac/lambda/TargetType14.out Mon Jan 21 11:16:28 2013 -0800 39.2 +++ b/test/tools/javac/lambda/TargetType14.out Mon Jan 21 20:13:56 2013 +0000 39.3 @@ -1,2 +1,2 @@ 39.4 -TargetType14.java:20:29: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: TargetType14.SAM<java.lang.String>, TargetType14.SAM<java.lang.Integer>) 39.5 +TargetType14.java:20:29: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.lower.bounds: java.lang.Integer, java.lang.String) 39.6 1 error
40.1 --- a/test/tools/javac/lambda/TargetType21.java Mon Jan 21 11:16:28 2013 -0800 40.2 +++ b/test/tools/javac/lambda/TargetType21.java Mon Jan 21 20:13:56 2013 +0000 40.3 @@ -26,8 +26,8 @@ 40.4 40.5 void test() { 40.6 call(x -> { throw new Exception(); }); //ambiguous 40.7 - call(x -> { System.out.println(""); }); //ok - resolves to call(SAM2) 40.8 - call(x -> { return (Object) null; }); //error - call(SAM3) is not applicable because of cyclic inference 40.9 - call(x -> { return null; }); ////ok - resolves to call(SAM1) 40.10 + call(x -> { System.out.println(""); }); //ambiguous 40.11 + call(x -> { return (Object) null; }); //cyclic inference 40.12 + call(x -> { return null; }); //ambiguous 40.13 } 40.14 }
41.1 --- a/test/tools/javac/lambda/TargetType21.out Mon Jan 21 11:16:28 2013 -0800 41.2 +++ b/test/tools/javac/lambda/TargetType21.out Mon Jan 21 20:13:56 2013 +0000 41.3 @@ -1,3 +1,6 @@ 41.4 -TargetType21.java:28:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM1), TargetType21, kindname.method, call(TargetType21.SAM2), TargetType21 41.5 -TargetType21.java:30:9: compiler.err.cant.apply.symbols: kindname.method, call, @737,{(compiler.misc.inapplicable.method: kindname.method, TargetType21, call(TargetType21.SAM1), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: java.lang.Object, java.lang.String)))),(compiler.misc.inapplicable.method: kindname.method, TargetType21, call(TargetType21.SAM2), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.unexpected.ret.val)))),(compiler.misc.inapplicable.method: kindname.method, TargetType21, <R,A>call(TargetType21.SAM3<R,A>), (compiler.misc.cyclic.inference: A))} 41.6 -2 errors 41.7 +TargetType21.java:28:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM2), TargetType21, kindname.method, <R,A>call(TargetType21.SAM3<R,A>), TargetType21 41.8 +TargetType21.java:28:14: compiler.err.incompatible.thrown.types.in.lambda: java.lang.Exception 41.9 +TargetType21.java:29:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM2), TargetType21, kindname.method, <R,A>call(TargetType21.SAM3<R,A>), TargetType21 41.10 +TargetType21.java:30:13: compiler.err.prob.found.req: (compiler.misc.cyclic.inference: A) 41.11 +TargetType21.java:31:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM1), TargetType21, kindname.method, <R,A>call(TargetType21.SAM3<R,A>), TargetType21 41.12 +5 errors
42.1 --- a/test/tools/javac/lambda/TargetType26.out Mon Jan 21 11:16:28 2013 -0800 42.2 +++ b/test/tools/javac/lambda/TargetType26.out Mon Jan 21 20:13:56 2013 +0000 42.3 @@ -1,2 +1,2 @@ 42.4 -TargetType26.java:16:7: compiler.err.cant.apply.symbol: kindname.method, call, Z, @340, kindname.class, TargetType26, (compiler.misc.cyclic.inference: Z) 42.5 +TargetType26.java:16:11: compiler.err.prob.found.req: (compiler.misc.cyclic.inference: Z) 42.6 1 error
43.1 --- a/test/tools/javac/lambda/TargetType27.out Mon Jan 21 11:16:28 2013 -0800 43.2 +++ b/test/tools/javac/lambda/TargetType27.out Mon Jan 21 20:13:56 2013 +0000 43.3 @@ -1,2 +1,2 @@ 43.4 -TargetType27.java:18:9: compiler.err.cant.apply.symbol: kindname.method, m, TargetType27.F<A,R>, @490, kindname.class, TargetType27, (compiler.misc.cyclic.inference: R) 43.5 +TargetType27.java:18:10: compiler.err.prob.found.req: (compiler.misc.cyclic.inference: R) 43.6 1 error
44.1 --- a/test/tools/javac/lambda/TargetType28.out Mon Jan 21 11:16:28 2013 -0800 44.2 +++ b/test/tools/javac/lambda/TargetType28.out Mon Jan 21 20:13:56 2013 +0000 44.3 @@ -1,3 +1,3 @@ 44.4 -TargetType28.java:20:32: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: TargetType28.SuperFoo<java.lang.Number>, TargetType28.SuperFoo<java.lang.String>) 44.5 -TargetType28.java:21:33: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: TargetType28.SuperFoo<java.lang.Number>, TargetType28.SuperFoo<java.lang.Integer>) 44.6 +TargetType28.java:20:32: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.eq.bounds: java.lang.Number, java.lang.Number,java.lang.String) 44.7 +TargetType28.java:21:33: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.eq.bounds: java.lang.Number, java.lang.Number,java.lang.Integer) 44.8 2 errors
45.1 --- a/test/tools/javac/lambda/TargetType39.out Mon Jan 21 11:16:28 2013 -0800 45.2 +++ b/test/tools/javac/lambda/TargetType39.out Mon Jan 21 20:13:56 2013 +0000 45.3 @@ -1,3 +1,3 @@ 45.4 -TargetType39.java:19:9: compiler.err.cant.apply.symbol: kindname.method, call, TargetType39.SAM<U,V>, @442, kindname.class, TargetType39, (compiler.misc.cyclic.inference: U) 45.5 -TargetType39.java:20:9: compiler.err.cant.apply.symbol: kindname.method, call, TargetType39.SAM<U,V>, @479, kindname.class, TargetType39, (compiler.misc.cyclic.inference: V) 45.6 +TargetType39.java:19:13: compiler.err.prob.found.req: (compiler.misc.cyclic.inference: U) 45.7 +TargetType39.java:20:13: compiler.err.prob.found.req: (compiler.misc.cyclic.inference: V) 45.8 2 errors
46.1 --- a/test/tools/javac/lambda/TargetType45.java Mon Jan 21 11:16:28 2013 -0800 46.2 +++ b/test/tools/javac/lambda/TargetType45.java Mon Jan 21 20:13:56 2013 +0000 46.3 @@ -3,7 +3,7 @@ 46.4 * @bug 8003280 46.5 * @summary Add lambda tests 46.6 * compiler crashes during flow analysis as it fails to report diagnostics during attribution 46.7 - * @compile/fail/ref=TargetType45.out -XDrawDiagnostics TargetType45.java 46.8 + * @compile TargetType45.java 46.9 */ 46.10 class TargetType45 { 46.11
47.1 --- a/test/tools/javac/lambda/TargetType45.out Mon Jan 21 11:16:28 2013 -0800 47.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 47.3 @@ -1,2 +0,0 @@ 47.4 -TargetType45.java:27:28: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.assignment.exists: U,V, (compiler.misc.inconvertible.types: TargetType45.Mapper<java.lang.String,java.lang.Integer>, TargetType45.Mapper<? super java.lang.Object,? extends java.lang.Integer>)) 47.5 -1 error
48.1 --- a/test/tools/javac/lambda/TargetType50.out Mon Jan 21 11:16:28 2013 -0800 48.2 +++ b/test/tools/javac/lambda/TargetType50.out Mon Jan 21 20:13:56 2013 +0000 48.3 @@ -1,3 +1,3 @@ 48.4 -TargetType50.java:25:28: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.eq.bounds: java.lang.String, java.lang.String,java.lang.Object) 48.5 -TargetType50.java:26:28: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.eq.bounds: java.lang.String, java.lang.String,java.lang.Object) 48.6 +TargetType50.java:25:28: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: TargetType50.Sink<java.lang.Object>, TargetType50.Sink<java.lang.String>) 48.7 +TargetType50.java:26:28: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: TargetType50.Sink<java.lang.Object>, TargetType50.Sink<java.lang.String>) 48.8 2 errors
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 49.2 +++ b/test/tools/javac/lambda/TargetType51.java Mon Jan 21 20:13:56 2013 +0000 49.3 @@ -0,0 +1,66 @@ 49.4 +/* 49.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 49.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 49.7 + * 49.8 + * This code is free software; you can redistribute it and/or modify it 49.9 + * under the terms of the GNU General Public License version 2 only, as 49.10 + * published by the Free Software Foundation. 49.11 + * 49.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 49.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 49.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 49.15 + * version 2 for more details (a copy is included in the LICENSE file that 49.16 + * accompanied this code). 49.17 + * 49.18 + * You should have received a copy of the GNU General Public License version 49.19 + * 2 along with this work; if not, write to the Free Software Foundation, 49.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 49.21 + * 49.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 49.23 + * or visit www.oracle.com if you need additional information or have any 49.24 + * questions. 49.25 + */ 49.26 + 49.27 +/* 49.28 + * @test 49.29 + * @summary smoke test for combinator-like stuck analysis 49.30 + * @author Maurizio Cimadamore 49.31 + * @compile TargetType51.java 49.32 + */ 49.33 + 49.34 +import java.util.Comparator; 49.35 + 49.36 +class TargetType51 { 49.37 + 49.38 + interface SimpleMapper<T, U> { 49.39 + T map(U t); 49.40 + } 49.41 + 49.42 + interface SimpleList<X> { 49.43 + SimpleList<X> sort(Comparator<? super X> c); 49.44 + } 49.45 + 49.46 + static class Person { 49.47 + String getName() { return ""; } 49.48 + } 49.49 + 49.50 + <T, U extends Comparable<? super U>> Comparator<T> comparing(SimpleMapper<U, T> mapper) { return null; } 49.51 + 49.52 + static class F<U extends Comparable<? super U>, T> { 49.53 + F(SimpleMapper<U, T> f) { } 49.54 + } 49.55 + 49.56 + void testAssignmentContext(SimpleList<Person> list, boolean cond) { 49.57 + SimpleList<Person> p1 = list.sort(comparing(Person::getName)); 49.58 + SimpleList<Person> p2 = list.sort(comparing(x->x.getName())); 49.59 + SimpleList<Person> p3 = list.sort(cond ? comparing(Person::getName) : comparing(x->x.getName())); 49.60 + SimpleList<Person> p4 = list.sort((cond ? comparing(Person::getName) : comparing(x->x.getName()))); 49.61 + } 49.62 + 49.63 + void testMethodContext(SimpleList<Person> list, boolean cond) { 49.64 + testMethodContext(list.sort(comparing(Person::getName)), true); 49.65 + testMethodContext(list.sort(comparing(x->x.getName())), true); 49.66 + testMethodContext(list.sort(cond ? comparing(Person::getName) : comparing(x->x.getName())), true); 49.67 + testMethodContext(list.sort((cond ? comparing(Person::getName) : comparing(x->x.getName()))), true); 49.68 + } 49.69 +}
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 50.2 +++ b/test/tools/javac/lambda/TargetType52.java Mon Jan 21 20:13:56 2013 +0000 50.3 @@ -0,0 +1,17 @@ 50.4 +/* 50.5 + * @test /nodynamiccopyright/ 50.6 + * @summary uncatched sam conversion failure exception lead to javac crash 50.7 + * @compile/fail/ref=TargetType52.out -XDrawDiagnostics TargetType52.java 50.8 + */ 50.9 +class TargetType52 { 50.10 + 50.11 + interface FI<T extends CharSequence, V extends java.util.AbstractList<T>> { 50.12 + T m(V p); 50.13 + } 50.14 + 50.15 + void m(FI<? extends CharSequence, ? extends java.util.ArrayList<? extends CharSequence>> fip) { } 50.16 + 50.17 + void test() { 50.18 + m(p -> p.get(0)); 50.19 + } 50.20 +}
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 51.2 +++ b/test/tools/javac/lambda/TargetType52.out Mon Jan 21 20:13:56 2013 +0000 51.3 @@ -0,0 +1,2 @@ 51.4 +TargetType52.java:15:9: compiler.err.cant.apply.symbol: kindname.method, m, TargetType52.FI<? extends java.lang.CharSequence,? extends java.util.ArrayList<? extends java.lang.CharSequence>>, @449, kindname.class, TargetType52, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.no.suitable.functional.intf.inst: TargetType52.FI<java.lang.CharSequence,java.util.ArrayList<? extends java.lang.CharSequence>>)) 51.5 +1 error
52.1 --- a/test/tools/javac/lambda/VoidCompatibility.java Mon Jan 21 11:16:28 2013 -0800 52.2 +++ b/test/tools/javac/lambda/VoidCompatibility.java Mon Jan 21 20:13:56 2013 +0000 52.3 @@ -3,7 +3,7 @@ 52.4 * @bug 8003280 52.5 * @summary Add lambda tests 52.6 * check that that void compatibility affects overloading as expected 52.7 - * @compile/fail/ref=VoidCompatibility.out -XDrawDiagnostics VoidCompatibility.java 52.8 + * @compile VoidCompatibility.java 52.9 */ 52.10 class VoidCompatibility { 52.11 52.12 @@ -14,13 +14,13 @@ 52.13 void schedule(Thunk<?> t) { } 52.14 52.15 void test() { 52.16 - schedule(() -> System.setProperty("done", "true")); //2 52.17 + schedule(() -> System.setProperty("done", "true")); //non-void most specific 52.18 schedule(() -> { System.setProperty("done", "true"); }); //1 52.19 schedule(() -> { return System.setProperty("done", "true"); }); //2 52.20 schedule(() -> System.out.println("done")); //1 52.21 schedule(() -> { System.out.println("done"); }); //1 52.22 schedule(Thread::yield); //1 52.23 - schedule(Thread::getAllStackTraces); //ambiguous 52.24 + schedule(Thread::getAllStackTraces); //non-void most specific 52.25 schedule(Thread::interrupted); //1 (most specific) 52.26 } 52.27 }
53.1 --- a/test/tools/javac/lambda/VoidCompatibility.out Mon Jan 21 11:16:28 2013 -0800 53.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 53.3 @@ -1,3 +0,0 @@ 53.4 -VoidCompatibility.java:17:9: compiler.err.ref.ambiguous: schedule, kindname.method, schedule(VoidCompatibility.Runnable), VoidCompatibility, kindname.method, schedule(VoidCompatibility.Thunk<?>), VoidCompatibility 53.5 -VoidCompatibility.java:23:9: compiler.err.ref.ambiguous: schedule, kindname.method, schedule(VoidCompatibility.Runnable), VoidCompatibility, kindname.method, schedule(VoidCompatibility.Thunk<?>), VoidCompatibility 53.6 -2 errors
54.1 --- a/test/tools/javac/lambda/lambdaExpression/SamConversionComboTest.java Mon Jan 21 11:16:28 2013 -0800 54.2 +++ b/test/tools/javac/lambda/lambdaExpression/SamConversionComboTest.java Mon Jan 21 20:13:56 2013 +0000 54.3 @@ -149,8 +149,7 @@ 54.4 return false; //ambiguous target type 54.5 } 54.6 else if(lambdaBody == LambdaBody.IMPLICIT) { 54.7 - if(returnValue != ReturnValue.INTEGER) //ambiguous target type 54.8 - return false; 54.9 + return false; 54.10 } 54.11 else { //explicit parameter type 54.12 if(fInterface.getParameterType().equals("Integer")) //ambiguous target type
55.1 --- a/test/tools/javac/lambda/methodReference/SamConversion.java Mon Jan 21 11:16:28 2013 -0800 55.2 +++ b/test/tools/javac/lambda/methodReference/SamConversion.java Mon Jan 21 20:13:56 2013 +0000 55.3 @@ -149,14 +149,6 @@ 55.4 test2(A::method3, 4); 55.5 test2(new A()::method4, 5); 55.6 test2(new A()::method5, 6); 55.7 - A a = new A(A::method1); //A(Foo f) called 55.8 - assertTrue(a.method2(1) == 11); 55.9 - assertTrue(a.method4(1) == 11); 55.10 - assertTrue(a.method5(1) == 11); 55.11 - A a2 = new A(new A()::method2); //A(Bar b) called 55.12 - assertTrue(a2.method2(1) == 12); 55.13 - assertTrue(a2.method4(1) == 12); 55.14 - assertTrue(a2.method5(1) == 12); 55.15 } 55.16 55.17 /** 55.18 @@ -279,7 +271,7 @@ 55.19 testConditionalExpression(false); 55.20 testLambdaExpressionBody(); 55.21 55.22 - assertTrue(assertionCount == 38); 55.23 + assertTrue(assertionCount == 32); 55.24 } 55.25 55.26 static class MyException extends Exception {}
56.1 --- a/test/tools/javac/lambda/methodReference/SamConversionComboTest.java Mon Jan 21 11:16:28 2013 -0800 56.2 +++ b/test/tools/javac/lambda/methodReference/SamConversionComboTest.java Mon Jan 21 20:13:56 2013 +0000 56.3 @@ -186,10 +186,7 @@ 56.4 if(context != Context.CONSTRUCTOR && fInterface != FInterface.C && methodDef == MethodDef.METHOD6) 56.5 //method that throws exceptions not thrown by the interface method is a mismatch 56.6 return false; 56.7 - if(context == Context.CONSTRUCTOR && 56.8 - methodReference != MethodReference.METHOD1 && 56.9 - methodReference != MethodReference.METHOD2 && 56.10 - methodReference != MethodReference.METHOD3)//ambiguous reference 56.11 + if(context == Context.CONSTRUCTOR) 56.12 return false; 56.13 return true; 56.14 }
57.1 --- a/test/tools/javac/lambda/typeInference/InferenceTest_neg5.out Mon Jan 21 11:16:28 2013 -0800 57.2 +++ b/test/tools/javac/lambda/typeInference/InferenceTest_neg5.out Mon Jan 21 20:13:56 2013 +0000 57.3 @@ -1,2 +1,2 @@ 57.4 -InferenceTest_neg5.java:14:13: compiler.err.cant.apply.symbol: kindname.method, method1, InferenceTest_neg5.SAM1<X>, @419, kindname.class, InferenceTest_neg5, (compiler.misc.cyclic.inference: X) 57.5 +InferenceTest_neg5.java:14:21: compiler.err.prob.found.req: (compiler.misc.cyclic.inference: X) 57.6 1 error
58.1 --- a/test/tools/javac/resolve/tests/PrimitiveOverReferenceVarargsAmbiguous.java Mon Jan 21 11:16:28 2013 -0800 58.2 +++ b/test/tools/javac/resolve/tests/PrimitiveOverReferenceVarargsAmbiguous.java Mon Jan 21 20:13:56 2013 +0000 58.3 @@ -23,44 +23,44 @@ 58.4 58.5 @TraceResolve(keys={"compiler.err.ref.ambiguous"}) 58.6 class PrimitiveOverReferenceVarargsAmbiguous { 58.7 - @Candidate(applicable=Phase.VARARGS, mostSpecific=false) 58.8 + @Candidate(applicable=Phase.VARARGS, mostSpecific=true) 58.9 static void m_byte(byte... b) {} 58.10 - @Candidate(applicable=Phase.VARARGS, mostSpecific=false) 58.11 + @Candidate(applicable=Phase.VARARGS) 58.12 static void m_byte(Byte... b) {} 58.13 58.14 - @Candidate(applicable=Phase.VARARGS, mostSpecific=false) 58.15 + @Candidate(applicable=Phase.VARARGS, mostSpecific=true) 58.16 static void m_short(short... s) {} 58.17 - @Candidate(applicable=Phase.VARARGS, mostSpecific=false) 58.18 + @Candidate(applicable=Phase.VARARGS) 58.19 static void m_short(Short... s) {} 58.20 58.21 - @Candidate(applicable=Phase.VARARGS, mostSpecific=false) 58.22 + @Candidate(applicable=Phase.VARARGS, mostSpecific=true) 58.23 static void m_int(int... i) {} 58.24 - @Candidate(applicable=Phase.VARARGS, mostSpecific=false) 58.25 + @Candidate(applicable=Phase.VARARGS) 58.26 static void m_int(Integer... i) {} 58.27 58.28 - @Candidate(applicable=Phase.VARARGS, mostSpecific=false) 58.29 + @Candidate(applicable=Phase.VARARGS, mostSpecific=true) 58.30 static void m_long(long... l) {} 58.31 - @Candidate(applicable=Phase.VARARGS, mostSpecific=false) 58.32 + @Candidate(applicable=Phase.VARARGS) 58.33 static void m_long(Long... l) {} 58.34 58.35 - @Candidate(applicable=Phase.VARARGS, mostSpecific=false) 58.36 + @Candidate(applicable=Phase.VARARGS, mostSpecific=true) 58.37 static void m_float(float... f) {} 58.38 - @Candidate(applicable=Phase.VARARGS, mostSpecific=false) 58.39 + @Candidate(applicable=Phase.VARARGS) 58.40 static void m_float(Float... f) {} 58.41 58.42 - @Candidate(applicable=Phase.VARARGS, mostSpecific=false) 58.43 + @Candidate(applicable=Phase.VARARGS, mostSpecific=true) 58.44 static void m_double(double... d) {} 58.45 - @Candidate(applicable=Phase.VARARGS, mostSpecific=false) 58.46 + @Candidate(applicable=Phase.VARARGS) 58.47 static void m_double(Double... d) {} 58.48 58.49 - @Candidate(applicable=Phase.VARARGS, mostSpecific=false) 58.50 + @Candidate(applicable=Phase.VARARGS, mostSpecific=true) 58.51 static void m_char(char... c) {} 58.52 - @Candidate(applicable=Phase.VARARGS, mostSpecific=false) 58.53 + @Candidate(applicable=Phase.VARARGS) 58.54 static void m_char(Character... c) {} 58.55 58.56 - @Candidate(applicable=Phase.VARARGS, mostSpecific=false) 58.57 + @Candidate(applicable=Phase.VARARGS, mostSpecific=true) 58.58 static void m_bool(boolean... z) {} 58.59 - @Candidate(applicable=Phase.VARARGS, mostSpecific=false) 58.60 + @Candidate(applicable=Phase.VARARGS) 58.61 static void m_bool(Boolean... z) {} 58.62 58.63 {