8003280: Add lambda tests

Turn on lambda expression, method reference and default method support

Reviewed-by: jjg
This commit is contained in:
Maurizio Cimadamore 2012-11-17 19:01:03 +00:00
parent c39f1d99b4
commit a494f0ab86
451 changed files with 15433 additions and 488 deletions

View file

@ -67,6 +67,7 @@ public class Flags {
if ((mask&NATIVE) != 0) flags.add(Flag.NATIVE);
if ((mask&INTERFACE) != 0) flags.add(Flag.INTERFACE);
if ((mask&ABSTRACT) != 0) flags.add(Flag.ABSTRACT);
if ((mask&DEFAULT) != 0) flags.add(Flag.DEFAULT);
if ((mask&STRICTFP) != 0) flags.add(Flag.STRICTFP);
if ((mask&BRIDGE) != 0) flags.add(Flag.BRIDGE);
if ((mask&SYNTHETIC) != 0) flags.add(Flag.SYNTHETIC);
@ -261,7 +262,7 @@ public class Flags {
* Flag that marks class as auxiliary, ie a non-public class following
* the public class in a source file, that could block implicit compilation.
*/
public static final long AUXILIARY = 1L<<43;
public static final long AUXILIARY = 1L<<44;
/** Modifier masks.
*/

View file

@ -438,7 +438,8 @@ public abstract class Symbol implements Element {
}
public Set<Modifier> getModifiers() {
return Flags.asModifierSet(flags());
long flags = flags();
return Flags.asModifierSet((flags & DEFAULT) != 0 ? flags & ~ABSTRACT : flags);
}
public Name getSimpleName() {
@ -475,6 +476,7 @@ public abstract class Symbol implements Element {
public String toString() { return other.toString(); }
public Symbol location() { return other.location(); }
public Symbol location(Type site, Types types) { return other.location(site, types); }
public Symbol baseSymbol() { return other; }
public Type erasure(Types types) { return other.erasure(types); }
public Type externalType(Types types) { return other.externalType(types); }
public boolean isLocal() { return other.isLocal(); }
@ -1192,7 +1194,7 @@ public abstract class Symbol implements Element {
// check for an inherited implementation
if ((flags() & ABSTRACT) != 0 ||
(other.flags() & ABSTRACT) == 0 ||
((other.flags() & ABSTRACT) == 0 && (other.flags() & DEFAULT) == 0) ||
!other.isOverridableIn(origin) ||
!this.isMemberOf(origin, types))
return false;
@ -1202,7 +1204,7 @@ public abstract class Symbol implements Element {
Type ot = types.memberType(origin.type, other);
return
types.isSubSignature(mt, ot) &&
(!checkResult || types.resultSubtype(mt, ot, Warner.noWarnings));
(!checkResult || types.resultSubtype(mt, ot, types.noWarnings));
}
private boolean isOverridableIn(TypeSymbol origin) {

View file

@ -83,6 +83,8 @@ public class Types {
final Name capturedName;
private final FunctionDescriptorLookupError functionDescriptorLookupError;
public final Warner noWarnings;
// <editor-fold defaultstate="collapsed" desc="Instantiating">
public static Types instance(Context context) {
Types instance = context.get(typesKey);
@ -106,6 +108,7 @@ public class Types {
messages = JavacMessages.instance(context);
diags = JCDiagnostic.Factory.instance(context);
functionDescriptorLookupError = new FunctionDescriptorLookupError();
noWarnings = new Warner(null);
}
// </editor-fold>
@ -296,7 +299,7 @@ public class Types {
* convertions to s?
*/
public boolean isConvertible(Type t, Type s) {
return isConvertible(t, s, Warner.noWarnings);
return isConvertible(t, s, noWarnings);
}
// </editor-fold>
@ -395,14 +398,9 @@ public class Types {
@Override
public boolean accepts(Symbol sym) {
return sym.kind == Kinds.MTH &&
(sym.flags() & ABSTRACT) != 0 &&
(sym.flags() & (ABSTRACT | DEFAULT)) == ABSTRACT &&
!overridesObjectMethod(origin, sym) &&
notOverridden(sym);
}
private boolean notOverridden(Symbol msym) {
Symbol impl = ((MethodSymbol)msym).implementation(origin, Types.this, false);
return impl == null || (impl.flags() & ABSTRACT) != 0;
(interfaceCandidates(origin.type, (MethodSymbol)sym).head.flags() & DEFAULT) == 0;
}
};
@ -593,7 +591,7 @@ public class Types {
* Is t an unchecked subtype of s?
*/
public boolean isSubtypeUnchecked(Type t, Type s) {
return isSubtypeUnchecked(t, s, Warner.noWarnings);
return isSubtypeUnchecked(t, s, noWarnings);
}
/**
* Is t an unchecked subtype of s?
@ -1196,7 +1194,7 @@ public class Types {
// <editor-fold defaultstate="collapsed" desc="isCastable">
public boolean isCastable(Type t, Type s) {
return isCastable(t, s, Warner.noWarnings);
return isCastable(t, s, noWarnings);
}
/**
@ -1259,7 +1257,7 @@ public class Types {
return true;
if (s.tag == TYPEVAR) {
if (isCastable(t, s.getUpperBound(), Warner.noWarnings)) {
if (isCastable(t, s.getUpperBound(), noWarnings)) {
warnStack.head.warn(LintCategory.UNCHECKED);
return true;
} else {
@ -1269,7 +1267,7 @@ public class Types {
if (t.isCompound()) {
Warner oldWarner = warnStack.head;
warnStack.head = Warner.noWarnings;
warnStack.head = noWarnings;
if (!visit(supertype(t), s))
return false;
for (Type intf : interfaces(t)) {
@ -1368,7 +1366,7 @@ public class Types {
case BOT:
return true;
case TYPEVAR:
if (isCastable(s, t, Warner.noWarnings)) {
if (isCastable(s, t, noWarnings)) {
warnStack.head.warn(LintCategory.UNCHECKED);
return true;
} else {
@ -1396,7 +1394,7 @@ public class Types {
case TYPEVAR:
if (isSubtype(t, s)) {
return true;
} else if (isCastable(t.bound, s, Warner.noWarnings)) {
} else if (isCastable(t.bound, s, noWarnings)) {
warnStack.head.warn(LintCategory.UNCHECKED);
return true;
} else {
@ -1535,7 +1533,7 @@ public class Types {
TypeVar tv = (TypeVar) t;
return !isCastable(tv.bound,
relaxBound(s),
Warner.noWarnings);
noWarnings);
}
if (s.tag != WILDCARD)
s = upperBound(s);
@ -1838,7 +1836,7 @@ public class Types {
// <editor-fold defaultstate="collapsed" desc="isAssignable">
public boolean isAssignable(Type t, Type s) {
return isAssignable(t, s, Warner.noWarnings);
return isAssignable(t, s, noWarnings);
}
/**
@ -2149,9 +2147,9 @@ public class Types {
}
};
public boolean isDirectSuperInterface(Type t, TypeSymbol tsym) {
for (Type t2 : interfaces(tsym.type)) {
if (isSameType(t, t2)) return true;
public boolean isDirectSuperInterface(TypeSymbol isym, TypeSymbol origin) {
for (Type i2 : interfaces(origin.type)) {
if (isym == i2.tsym) return true;
}
return false;
}
@ -2224,7 +2222,9 @@ public class Types {
* Return list of bounds of the given type variable.
*/
public List<Type> getBounds(TypeVar t) {
if (t.bound.isErroneous() || !t.bound.isCompound())
if (t.bound.hasTag(NONE))
return List.nil();
else if (t.bound.isErroneous() || !t.bound.isCompound())
return List.of(t.bound);
else if ((erasure(t).tsym.flags() & INTERFACE) == 0)
return interfaces(t).prepend(supertype(t));
@ -2319,10 +2319,6 @@ public class Types {
return false;
}
public boolean overridesObjectMethod(Symbol msym) {
return ((MethodSymbol)msym).implementation(syms.objectType.tsym, this, true) != null;
}
// <editor-fold defaultstate="collapsed" desc="Determining method implementation in given site">
class ImplementationCache {
@ -2471,11 +2467,7 @@ public class Types {
//where
public List<MethodSymbol> interfaceCandidates(Type site, MethodSymbol ms) {
return interfaceCandidates(site, ms, false);
}
public List<MethodSymbol> interfaceCandidates(Type site, MethodSymbol ms, boolean intfOnly) {
Filter<Symbol> filter = new MethodFilter(ms, site, intfOnly);
Filter<Symbol> filter = new MethodFilter(ms, site);
List<MethodSymbol> candidates = List.nil();
for (Symbol s : membersClosure(site, false).getElements(filter)) {
if (!site.tsym.isInterface() && !s.owner.isInterface()) {
@ -2514,17 +2506,14 @@ public class Types {
Symbol msym;
Type site;
boolean intfOnly;
MethodFilter(Symbol msym, Type site, boolean intfOnly) {
MethodFilter(Symbol msym, Type site) {
this.msym = msym;
this.site = site;
this.intfOnly = intfOnly;
}
public boolean accepts(Symbol s) {
return s.kind == Kinds.MTH &&
(!intfOnly || s.owner.isInterface()) &&
s.name == msym.name &&
s.isInheritedIn(site.tsym, Types.this) &&
overrideEquivalent(memberType(site, s), memberType(site, msym));
@ -3462,11 +3451,11 @@ public class Types {
*/
public boolean returnTypeSubstitutable(Type r1, Type r2) {
if (hasSameArgs(r1, r2))
return resultSubtype(r1, r2, Warner.noWarnings);
return resultSubtype(r1, r2, noWarnings);
else
return covariantReturnType(r1.getReturnType(),
erasure(r2.getReturnType()),
Warner.noWarnings);
noWarnings);
}
public boolean returnTypeSubstitutable(Type r1,

View file

@ -133,7 +133,7 @@ public class Attr extends JCTree.Visitor {
allowCovariantReturns = source.allowCovariantReturns();
allowAnonOuterThis = source.allowAnonOuterThis();
allowStringsInSwitch = source.allowStringsInSwitch();
allowPoly = source.allowPoly() && options.isSet("allowPoly");
allowPoly = source.allowPoly();
allowLambda = source.allowLambda();
allowDefaultMethods = source.allowDefaultMethods();
sourceName = source.name;
@ -179,14 +179,14 @@ public class Attr extends JCTree.Visitor {
*/
boolean allowCovariantReturns;
/** Switch: support default methods ?
*/
boolean allowDefaultMethods;
/** Switch: support lambda expressions ?
*/
boolean allowLambda;
/** Switch: support default methods ?
*/
boolean allowDefaultMethods;
/** Switch: allow references to surrounding object from anonymous
* objects during constructor call?
*/
@ -524,6 +524,10 @@ public class Attr extends JCTree.Visitor {
protected ResultInfo dup(Type newPt) {
return new ResultInfo(pkind, newPt, checkContext);
}
protected ResultInfo dup(CheckContext newContext) {
return new ResultInfo(pkind, pt, newContext);
}
}
class RecoveryInfo extends ResultInfo {
@ -540,7 +544,7 @@ public class Attr extends JCTree.Visitor {
}
@Override
public void report(DiagnosticPosition pos, JCDiagnostic details) {
//do nothing
chk.basicHandler.report(pos, details);
}
});
}
@ -595,8 +599,10 @@ public class Attr extends JCTree.Visitor {
this.env = env;
this.resultInfo = resultInfo;
tree.accept(this);
if (tree == breakTree)
if (tree == breakTree &&
resultInfo.checkContext.deferredAttrContext().mode == AttrMode.CHECK) {
throw new BreakAttr(env);
}
return result;
} catch (CompletionFailure ex) {
tree.type = syms.errType;
@ -903,7 +909,7 @@ public class Attr extends JCTree.Visitor {
localEnv.info.lint = lint;
if (isDefaultMethod && types.overridesObjectMethod(m)) {
if (isDefaultMethod && types.overridesObjectMethod(m.enclClass(), m)) {
log.error(tree, "default.overrides.object.member", m.name, Kinds.kindName(m.location()), m.location());
}
@ -1390,13 +1396,14 @@ public class Attr extends JCTree.Visitor {
if (!standaloneConditional && resultInfo.pt.hasTag(VOID)) {
//cannot get here (i.e. it means we are returning from void method - which is already an error)
resultInfo.checkContext.report(tree, diags.fragment("conditional.target.cant.be.void"));
result = tree.type = types.createErrorType(resultInfo.pt);
return;
}
ResultInfo condInfo = standaloneConditional ?
unknownExprInfo :
new ResultInfo(VAL, pt(), new Check.NestedCheckContext(resultInfo.checkContext) {
resultInfo.dup(new Check.NestedCheckContext(resultInfo.checkContext) {
//this will use enclosing check context to check compatibility of
//subexpression against target type; if we are in a method check context,
//depending on whether boxing is allowed, we could have incompatibilities
@ -1419,11 +1426,11 @@ public class Attr extends JCTree.Visitor {
result = check(tree, owntype, VAL, resultInfo);
}
//where
@SuppressWarnings("fallthrough")
private boolean isBooleanOrNumeric(Env<AttrContext> env, JCExpression tree) {
switch (tree.getTag()) {
case LITERAL: return ((JCLiteral)tree).typetag.isSubRangeOf(DOUBLE) ||
((JCLiteral)tree).typetag == BOOLEAN;
((JCLiteral)tree).typetag == BOOLEAN ||
((JCLiteral)tree).typetag == BOT;
case LAMBDA: case REFERENCE: return false;
case PARENS: return isBooleanOrNumeric(env, ((JCParens)tree).expr);
case CONDEXPR:
@ -1612,19 +1619,23 @@ public class Attr extends JCTree.Visitor {
// it conforms to result type of enclosing method.
if (tree.expr != null) {
if (env.info.returnResult.pt.hasTag(VOID)) {
log.error(tree.expr.pos(),
"cant.ret.val.from.meth.decl.void");
env.info.returnResult.checkContext.report(tree.expr.pos(),
diags.fragment("unexpected.ret.val"));
}
attribTree(tree.expr, env, env.info.returnResult);
} else if (!env.info.returnResult.pt.hasTag(VOID)) {
log.error(tree.pos(), "missing.ret.val");
env.info.returnResult.checkContext.report(tree.pos(),
diags.fragment("missing.ret.val"));
}
}
result = null;
}
public void visitThrow(JCThrow tree) {
attribExpr(tree.expr, env, syms.throwableType);
Type owntype = attribExpr(tree.expr, env, allowPoly ? Type.noType : syms.throwableType);
if (allowPoly) {
chk.checkType(tree, owntype, syms.throwableType);
}
result = null;
}
@ -2068,7 +2079,7 @@ public class Attr extends JCTree.Visitor {
resultInfo.checkContext.inferenceContext().free(resultInfo.pt) ? Type.noType : pt());
Type inferred = deferredAttr.attribSpeculative(tree, env, findDiamondResult).type;
if (!inferred.isErroneous() &&
types.isAssignable(inferred, pt().hasTag(NONE) ? syms.objectType : pt(), Warner.noWarnings)) {
types.isAssignable(inferred, pt().hasTag(NONE) ? syms.objectType : pt(), types.noWarnings)) {
String key = types.isSameType(clazztype, inferred) ?
"diamond.redundant.args" :
"diamond.redundant.args.1";
@ -2172,7 +2183,7 @@ public class Attr extends JCTree.Visitor {
}
//create an environment for attribution of the lambda expression
final Env<AttrContext> localEnv = lambdaEnv(that, env);
boolean needsRecovery = resultInfo.checkContext.deferredAttrContext() == deferredAttr.emptyDeferredAttrContext ||
boolean needsRecovery =
resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK;
try {
List<Type> explicitParamTypes = null;
@ -2182,10 +2193,16 @@ public class Attr extends JCTree.Visitor {
explicitParamTypes = TreeInfo.types(that.params);
}
Type target = infer.instantiateFunctionalInterface(that, pt(), explicitParamTypes, resultInfo.checkContext);
Type lambdaType = (target == Type.recoveryType) ?
fallbackDescriptorType(that) :
types.findDescriptorType(target);
Type target;
Type lambdaType;
if (pt() != Type.recoveryType) {
target = infer.instantiateFunctionalInterface(that, pt(), explicitParamTypes, resultInfo.checkContext);
lambdaType = types.findDescriptorType(target);
chk.checkFunctionalInterface(that, target);
} else {
target = Type.recoveryType;
lambdaType = fallbackDescriptorType(that);
}
if (!TreeInfo.isExplicitLambda(that)) {
//add param type info in the AST
@ -2250,7 +2267,7 @@ public class Attr extends JCTree.Visitor {
checkLambdaCompatible(that, lambdaType, resultInfo.checkContext, isSpeculativeRound);
if (!isSpeculativeRound) {
checkAccessibleFunctionalDescriptor(that, localEnv, resultInfo.checkContext.inferenceContext(), lambdaType);
checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), lambdaType, target);
}
result = check(that, target, VAL, resultInfo);
} catch (Types.FunctionDescriptorLookupError ex) {
@ -2285,17 +2302,22 @@ public class Attr extends JCTree.Visitor {
return null;
}
private void checkAccessibleFunctionalDescriptor(final DiagnosticPosition pos,
final Env<AttrContext> env, final InferenceContext inferenceContext, final Type desc) {
if (inferenceContext.free(desc)) {
inferenceContext.addFreeTypeListener(List.of(desc), new FreeTypeListener() {
private void checkAccessibleTypes(final DiagnosticPosition pos, final Env<AttrContext> env, final InferenceContext inferenceContext, final Type... ts) {
checkAccessibleTypes(pos, env, inferenceContext, List.from(ts));
}
private void checkAccessibleTypes(final DiagnosticPosition pos, final Env<AttrContext> env, final InferenceContext inferenceContext, final List<Type> ts) {
if (inferenceContext.free(ts)) {
inferenceContext.addFreeTypeListener(ts, new FreeTypeListener() {
@Override
public void typesInferred(InferenceContext inferenceContext) {
checkAccessibleFunctionalDescriptor(pos, env, inferenceContext, inferenceContext.asInstType(desc, types));
checkAccessibleTypes(pos, env, inferenceContext, inferenceContext.asInstTypes(ts, types));
}
});
} else {
chk.checkAccessibleFunctionalDescriptor(pos, env, desc);
for (Type t : ts) {
rs.checkAccessibleType(env, t);
}
}
}
@ -2411,15 +2433,20 @@ public class Attr extends JCTree.Visitor {
typeargtypes = attribTypes(that.typeargs, localEnv);
}
Type target = infer.instantiateFunctionalInterface(that, pt(), null, resultInfo.checkContext);
Type desc = (target == Type.recoveryType) ?
fallbackDescriptorType(that) :
types.findDescriptorType(target);
Type target;
Type desc;
if (pt() != Type.recoveryType) {
target = infer.instantiateFunctionalInterface(that, pt(), null, resultInfo.checkContext);
desc = types.findDescriptorType(target);
chk.checkFunctionalInterface(that, target);
} else {
target = Type.recoveryType;
desc = fallbackDescriptorType(that);
}
List<Type> argtypes = desc.getParameterTypes();
boolean allowBoxing =
resultInfo.checkContext.deferredAttrContext() == deferredAttr.emptyDeferredAttrContext ||
resultInfo.checkContext.deferredAttrContext().phase.isBoxingRequired();
Pair<Symbol, Resolve.ReferenceLookupHelper> refResult = rs.resolveMemberReference(that.pos(), localEnv, that,
that.expr.type, that.name, argtypes, typeargtypes, allowBoxing);
@ -2455,6 +2482,12 @@ public class Attr extends JCTree.Visitor {
JCDiagnostic diag = diags.create(diagKind, log.currentSource(), that,
"invalid.mref", Kinds.kindName(that.getMode()), detailsDiag);
if (targetError && target == Type.recoveryType) {
//a target error doesn't make sense during recovery stage
//as we don't know what actual parameter types are
result = that.type = target;
return;
} else {
if (targetError) {
resultInfo.checkContext.report(that, diag);
} else {
@ -2463,10 +2496,11 @@ public class Attr extends JCTree.Visitor {
result = that.type = types.createErrorType(target);
return;
}
}
if (desc.getReturnType() == Type.recoveryType) {
// stop here
result = that.type = types.createErrorType(target);
result = that.type = target;
return;
}
@ -2492,7 +2526,7 @@ public class Attr extends JCTree.Visitor {
resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE;
checkReferenceCompatible(that, desc, refType, resultInfo.checkContext, isSpeculativeRound);
if (!isSpeculativeRound) {
checkAccessibleFunctionalDescriptor(that, localEnv, resultInfo.checkContext.inferenceContext(), desc);
checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), desc, target);
}
result = check(that, target, VAL, resultInfo);
} catch (Types.FunctionDescriptorLookupError ex) {
@ -2526,7 +2560,7 @@ public class Attr extends JCTree.Visitor {
if (!returnType.hasTag(VOID) && !resType.hasTag(VOID)) {
if (resType.isErroneous() ||
new LambdaReturnContext(checkContext).compatible(resType, returnType, Warner.noWarnings)) {
new LambdaReturnContext(checkContext).compatible(resType, returnType, types.noWarnings)) {
incompatibleReturnType = null;
}
}
@ -3039,15 +3073,52 @@ public class Attr extends JCTree.Visitor {
Symbol sym,
Env<AttrContext> env,
ResultInfo resultInfo) {
Type pt = resultInfo.pt.hasTag(FORALL) || resultInfo.pt.hasTag(METHOD) ?
resultInfo.pt.map(deferredAttr.new DeferredTypeMap(AttrMode.SPECULATIVE, sym, env.info.pendingResolutionPhase)) :
resultInfo.pt;
return (resultInfo.pt.hasTag(FORALL) || resultInfo.pt.hasTag(METHOD)) ?
checkMethodId(tree, site, sym, env, resultInfo) :
checkIdInternal(tree, site, sym, resultInfo.pt, env, resultInfo);
}
DeferredAttr.DeferredTypeMap recoveryMap =
deferredAttr.new RecoveryDeferredTypeMap(AttrMode.CHECK, sym, env.info.pendingResolutionPhase);
Type checkMethodId(JCTree tree,
Type site,
Symbol sym,
Env<AttrContext> env,
ResultInfo resultInfo) {
boolean isPolymorhicSignature =
sym.kind == MTH && ((MethodSymbol)sym.baseSymbol()).isSignaturePolymorphic(types);
return isPolymorhicSignature ?
checkSigPolyMethodId(tree, site, sym, env, resultInfo) :
checkMethodIdInternal(tree, site, sym, env, resultInfo);
}
Type checkSigPolyMethodId(JCTree tree,
Type site,
Symbol sym,
Env<AttrContext> env,
ResultInfo resultInfo) {
//recover original symbol for signature polymorphic methods
checkMethodIdInternal(tree, site, sym.baseSymbol(), env, resultInfo);
env.info.pendingResolutionPhase = Resolve.MethodResolutionPhase.BASIC;
return sym.type;
}
Type checkMethodIdInternal(JCTree tree,
Type site,
Symbol sym,
Env<AttrContext> env,
ResultInfo resultInfo) {
Type pt = resultInfo.pt.map(deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, sym, env.info.pendingResolutionPhase));
Type owntype = checkIdInternal(tree, site, sym, pt, env, resultInfo);
resultInfo.pt.map(deferredAttr.new RecoveryDeferredTypeMap(AttrMode.CHECK, sym, env.info.pendingResolutionPhase));
return owntype;
}
Type checkIdInternal(JCTree tree,
Type site,
Symbol sym,
Type pt,
Env<AttrContext> env,
ResultInfo resultInfo) {
if (pt.isErroneous()) {
Type.map(resultInfo.pt.getParameterTypes(), recoveryMap);
return types.createErrorType(site);
}
Type owntype; // The computed type of this identifier occurrence.
@ -3132,7 +3203,6 @@ public class Attr extends JCTree.Visitor {
break;
}
case PCK: case ERR:
Type.map(resultInfo.pt.getParameterTypes(), recoveryMap);
owntype = sym.type;
break;
default:
@ -3288,21 +3358,21 @@ public class Attr extends JCTree.Visitor {
}
}
if (env.info.defaultSuperCallSite != null &&
!types.interfaceCandidates(env.enclClass.type, (MethodSymbol)sym, true).contains(sym)) {
Symbol ovSym = null;
for (MethodSymbol msym : types.interfaceCandidates(env.enclClass.type, (MethodSymbol)sym, true)) {
if (msym.overrides(sym, msym.enclClass(), types, true)) {
for (Type i : types.interfaces(env.enclClass.type)) {
if (i.tsym.isSubClass(msym.owner, types)) {
ovSym = i.tsym;
if (env.info.defaultSuperCallSite != null) {
for (Type sup : types.interfaces(env.enclClass.type).prepend(types.supertype((env.enclClass.type)))) {
if (!sup.tsym.isSubClass(sym.enclClass(), types) ||
types.isSameType(sup, env.info.defaultSuperCallSite)) continue;
List<MethodSymbol> icand_sup =
types.interfaceCandidates(sup, (MethodSymbol)sym);
if (icand_sup.nonEmpty() &&
icand_sup.head != sym &&
icand_sup.head.overrides(sym, icand_sup.head.enclClass(), types, true)) {
log.error(env.tree.pos(), "illegal.default.super.call", env.info.defaultSuperCallSite,
diags.fragment("overridden.default", sym, sup));
break;
}
}
}
}
log.error(env.tree.pos(), "illegal.default.super.call", env.info.defaultSuperCallSite,
diags.fragment("overridden.default", sym, ovSym));
env.info.defaultSuperCallSite = null;
}
// Compute the identifier's instantiated type.

View file

@ -120,8 +120,7 @@ public class Check {
allowCovariantReturns = source.allowCovariantReturns();
allowSimplifiedVarargs = source.allowSimplifiedVarargs();
allowDefaultMethods = source.allowDefaultMethods();
allowStrictMethodClashCheck = source.allowStrictMethodClashCheck() &&
options.isSet("strictMethodClashCheck"); //pre-lambda guard
allowStrictMethodClashCheck = source.allowStrictMethodClashCheck();
complexInference = options.isSet("complexinference");
warnOnSyntheticConflicts = options.isSet("warnOnSyntheticConflicts");
suppressAbortOnBadClassFile = options.isSet("suppressAbortOnBadClassFile");
@ -451,8 +450,6 @@ public class Check {
public Infer.InferenceContext inferenceContext();
public DeferredAttr.DeferredAttrContext deferredAttrContext();
public boolean allowBoxing();
}
/**
@ -487,10 +484,6 @@ public class Check {
public DeferredAttrContext deferredAttrContext() {
return enclosingContext.deferredAttrContext();
}
public boolean allowBoxing() {
return enclosingContext.allowBoxing();
}
}
/**
@ -515,10 +508,6 @@ public class Check {
public DeferredAttrContext deferredAttrContext() {
return deferredAttr.emptyDeferredAttrContext;
}
public boolean allowBoxing() {
return true;
}
};
/** Check that a given type is assignable to a given proto-type.
@ -625,7 +614,7 @@ public class Check {
a = types.upperBound(a);
return types.isSubtype(a, bound);
} else if (a.isExtendsBound()) {
return types.isCastable(bound, types.upperBound(a), Warner.noWarnings);
return types.isCastable(bound, types.upperBound(a), types.noWarnings);
} else if (a.isSuperBound()) {
return !types.notSoftSubtype(types.lowerBound(a), bound);
}
@ -909,6 +898,7 @@ public class Check {
"unchecked.generic.array.creation",
argtype);
}
if (!((MethodSymbol)sym.baseSymbol()).isSignaturePolymorphic(types)) {
Type elemtype = types.elemtype(argtype);
switch (tree.getTag()) {
case APPLY:
@ -924,6 +914,7 @@ public class Check {
throw new AssertionError(""+tree);
}
}
}
return owntype;
}
//where
@ -937,65 +928,6 @@ public class Check {
return;
}
void checkAccessibleFunctionalDescriptor(DiagnosticPosition pos, Env<AttrContext> env, Type desc) {
AccessChecker accessChecker = new AccessChecker(env);
//check args accessibility (only if implicit parameter types)
for (Type arg : desc.getParameterTypes()) {
if (!accessChecker.visit(arg)) {
log.error(pos, "cant.access.arg.type.in.functional.desc", arg);
return;
}
}
//check return type accessibility
if (!accessChecker.visit(desc.getReturnType())) {
log.error(pos, "cant.access.return.in.functional.desc", desc.getReturnType());
return;
}
//check thrown types accessibility
for (Type thrown : desc.getThrownTypes()) {
if (!accessChecker.visit(thrown)) {
log.error(pos, "cant.access.thrown.in.functional.desc", thrown);
return;
}
}
}
class AccessChecker extends Types.UnaryVisitor<Boolean> {
Env<AttrContext> env;
AccessChecker(Env<AttrContext> env) {
this.env = env;
}
Boolean visit(List<Type> ts) {
for (Type t : ts) {
if (!visit(t))
return false;
}
return true;
}
public Boolean visitType(Type t, Void s) {
return true;
}
@Override
public Boolean visitArrayType(ArrayType t, Void s) {
return visit(t.elemtype);
}
@Override
public Boolean visitClassType(ClassType t, Void s) {
return rs.isAccessible(env, t, true) &&
visit(t.getTypeArguments());
}
@Override
public Boolean visitWildcardType(WildcardType t, Void s) {
return visit(t.type);
}
};
/**
* Check that type 't' is a valid instantiation of a generic class
* (see JLS 4.5)
@ -1919,8 +1851,8 @@ public class Check {
types.isSameType(rt1, rt2) ||
!rt1.isPrimitiveOrVoid() &&
!rt2.isPrimitiveOrVoid() &&
(types.covariantReturnType(rt1, rt2, Warner.noWarnings) ||
types.covariantReturnType(rt2, rt1, Warner.noWarnings)) ||
(types.covariantReturnType(rt1, rt2, types.noWarnings) ||
types.covariantReturnType(rt2, rt1, types.noWarnings)) ||
checkCommonOverriderIn(s1,s2,site);
if (!compat) {
log.error(pos, "types.incompatible.diff.ret",
@ -1965,8 +1897,8 @@ public class Check {
boolean compat =
!rt13.isPrimitiveOrVoid() &&
!rt23.isPrimitiveOrVoid() &&
(types.covariantReturnType(rt13, rt1, Warner.noWarnings) &&
types.covariantReturnType(rt23, rt2, Warner.noWarnings));
(types.covariantReturnType(rt13, rt1, types.noWarnings) &&
types.covariantReturnType(rt23, rt2, types.noWarnings));
if (compat)
return true;
}
@ -2280,19 +2212,33 @@ public class Check {
c.flags_field |= ACYCLIC;
}
/**
* Check that functional interface methods would make sense when seen
* from the perspective of the implementing class
*/
void checkFunctionalInterface(JCTree tree, Type funcInterface) {
ClassType c = new ClassType(Type.noType, List.<Type>nil(), null);
ClassSymbol csym = new ClassSymbol(0, names.empty, c, syms.noSymbol);
c.interfaces_field = List.of(funcInterface);
c.supertype_field = syms.objectType;
c.tsym = csym;
csym.members_field = new Scope(csym);
csym.completer = null;
checkImplementations(tree, csym, csym);
}
/** Check that all methods which implement some
* method conform to the method they implement.
* @param tree The class definition whose members are checked.
*/
void checkImplementations(JCClassDecl tree) {
checkImplementations(tree, tree.sym);
checkImplementations(tree, tree.sym, tree.sym);
}
//where
/** Check that all methods which implement some
* method in `ic' conform to the method they implement.
*/
void checkImplementations(JCClassDecl tree, ClassSymbol ic) {
ClassSymbol origin = tree.sym;
void checkImplementations(JCTree tree, ClassSymbol origin, ClassSymbol ic) {
for (List<Type> l = types.closure(ic.type); l.nonEmpty(); l = l.tail) {
ClassSymbol lc = (ClassSymbol)l.head.tsym;
if ((allowGenerics || origin != lc) && (lc.flags() & ABSTRACT) != 0) {

View file

@ -38,14 +38,13 @@ import com.sun.tools.javac.tree.JCTree.*;
import javax.tools.JavaFileObject;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.WeakHashMap;
import static com.sun.tools.javac.code.TypeTag.DEFERRED;
import static com.sun.tools.javac.code.TypeTag.NONE;
import static com.sun.tools.javac.code.TypeTag.*;
import static com.sun.tools.javac.tree.JCTree.Tag.*;
/**
@ -136,19 +135,6 @@ public class DeferredAttr extends JCTree.Visitor {
}
}
/**
* Clone a speculative cache entry as a fresh entry associated
* with a new method (this maybe required to fixup speculative cache
* misses after Resolve.access())
*/
void dupAllTo(Symbol from, Symbol to) {
Assert.check(cache.get(to) == null);
List<Entry> entries = cache.get(from);
if (entries != null) {
cache.put(to, entries);
}
}
/**
* Retrieve a speculative cache entry corresponding to given symbol
* and resolution phase
@ -194,7 +180,7 @@ public class DeferredAttr extends JCTree.Visitor {
DeferredAttrContext deferredAttrContext =
resultInfo.checkContext.deferredAttrContext();
Assert.check(deferredAttrContext != emptyDeferredAttrContext);
List<Type> stuckVars = stuckVars(tree, resultInfo);
List<Type> stuckVars = stuckVars(tree, env, resultInfo);
if (stuckVars.nonEmpty()) {
deferredAttrContext.addDeferredAttrNode(this, resultInfo, stuckVars);
return Type.noType;
@ -275,6 +261,10 @@ public class DeferredAttr extends JCTree.Visitor {
@Override
public void visitClassDef(JCClassDecl tree) {
ClassSymbol csym = tree.sym;
//if something went wrong during method applicability check
//it is possible that nested expressions inside argument expression
//are left unchecked - in such cases there's nothing to clean up.
if (csym == null) return;
enter.typeEnvs.remove(csym);
chk.compiled.remove(csym.flatname);
syms.classes.remove(csym.flatname);
@ -333,7 +323,7 @@ public class DeferredAttr extends JCTree.Visitor {
*/
void complete() {
while (!deferredAttrNodes.isEmpty()) {
Set<Type> stuckVars = new HashSet<Type>();
Set<Type> stuckVars = new LinkedHashSet<Type>();
boolean progress = false;
//scan a defensive copy of the node list - this is because a deferred
//attribution round can add new nodes to the list
@ -407,7 +397,7 @@ public class DeferredAttr extends JCTree.Visitor {
/** an empty deferred attribution context - all methods throw exceptions */
final DeferredAttrContext emptyDeferredAttrContext =
new DeferredAttrContext(null, null, null, null) {
new DeferredAttrContext(AttrMode.CHECK, null, MethodResolutionPhase.BOX, null) {
@Override
void addDeferredAttrNode(DeferredType dt, ResultInfo ri, List<Type> stuckVars) {
Assert.error("Empty deferred context!");
@ -471,13 +461,13 @@ public class DeferredAttr extends JCTree.Visitor {
public class RecoveryDeferredTypeMap extends DeferredTypeMap {
public RecoveryDeferredTypeMap(AttrMode mode, Symbol msym, MethodResolutionPhase phase) {
super(mode, msym, phase);
super(mode, msym, phase != null ? phase : MethodResolutionPhase.BOX);
}
@Override
protected Type typeOf(DeferredType dt) {
Type owntype = super.typeOf(dt);
return owntype.hasTag(NONE) ?
return owntype == Type.noType ?
recover(dt) : owntype;
}
@ -495,29 +485,20 @@ public class DeferredAttr extends JCTree.Visitor {
*/
private Type recover(DeferredType dt) {
dt.check(attr.new RecoveryInfo(deferredAttrContext));
switch (TreeInfo.skipParens(dt.tree).getTag()) {
case LAMBDA:
case REFERENCE:
case CONDEXPR:
//propagate those deferred types to the
//diagnostic formatter
return dt;
default:
return super.apply(dt);
}
}
}
/**
* Retrieves the list of inference variables that need to be inferred before
* an AST node can be type-checked
*/
@SuppressWarnings("fallthrough")
List<Type> stuckVars(JCTree tree, ResultInfo resultInfo) {
List<Type> stuckVars(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) {
if (resultInfo.pt.hasTag(NONE) || resultInfo.pt.isErroneous()) {
return List.nil();
} else {
StuckChecker sc = new StuckChecker(resultInfo);
StuckChecker sc = new StuckChecker(resultInfo, env);
sc.scan(tree);
return List.from(sc.stuckVars);
}
@ -534,7 +515,8 @@ public class DeferredAttr extends JCTree.Visitor {
Type pt;
Filter<JCTree> treeFilter;
Infer.InferenceContext inferenceContext;
Set<Type> stuckVars = new HashSet<Type>();
Set<Type> stuckVars = new LinkedHashSet<Type>();
Env<AttrContext> env;
final Filter<JCTree> argsFilter = new Filter<JCTree>() {
public boolean accepts(JCTree t) {
@ -563,10 +545,11 @@ public class DeferredAttr extends JCTree.Visitor {
}
};
StuckChecker(ResultInfo resultInfo) {
StuckChecker(ResultInfo resultInfo, Env<AttrContext> env) {
this.pt = resultInfo.pt;
this.inferenceContext = resultInfo.checkContext.inferenceContext();
this.treeFilter = argsFilter;
this.env = env;
}
@Override
@ -616,6 +599,7 @@ public class DeferredAttr extends JCTree.Visitor {
if (!types.isFunctionalInterface(pt.tsym)) {
return;
}
Type descType = types.findDescriptorType(pt);
List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes());
stuckVars.addAll(freeArgVars);

View file

@ -272,9 +272,7 @@ public class Flow {
Source source = Source.instance(context);
allowImprovedRethrowAnalysis = source.allowImprovedRethrowAnalysis();
allowImprovedCatchAnalysis = source.allowImprovedCatchAnalysis();
Options options = Options.instance(context);
allowEffectivelyFinalInInnerClasses = source.allowEffectivelyFinalInInnerClasses() &&
options.isSet("allowEffectivelyFinalInInnerClasses"); //pre-lambda guard
allowEffectivelyFinalInInnerClasses = source.allowEffectivelyFinalInInnerClasses();
}
/**

View file

@ -501,10 +501,10 @@ public class Infer {
}
for (Type t : funcInterfaceContext.undetvars) {
UndetVar uv = (UndetVar)t;
minimizeInst(uv, Warner.noWarnings);
minimizeInst(uv, types.noWarnings);
if (uv.inst == null &&
Type.filter(uv.getBounds(InferenceBound.UPPER), boundFilter).nonEmpty()) {
maximizeInst(uv, Warner.noWarnings);
maximizeInst(uv, types.noWarnings);
}
}
@ -801,7 +801,7 @@ public class Infer {
for (Type t : varsToSolve) {
UndetVar uv = (UndetVar)asFree(t, types);
if (uv.inst == null) {
infer.minimizeInst(uv, Warner.noWarnings);
infer.minimizeInst(uv, types.noWarnings);
if (uv.inst != null) {
progress = true;
}

View file

@ -682,7 +682,7 @@ public class Lower extends TreeTranslator {
/** Look up a method in a given scope.
*/
private MethodSymbol lookupMethod(DiagnosticPosition pos, Name name, Type qual, List<Type> args) {
return rs.resolveInternalMethod(pos, attrEnv, qual, name, args, null);
return rs.resolveInternalMethod(pos, attrEnv, qual, name, args, List.<Type>nil());
}
/** Look up a constructor.
@ -3636,13 +3636,13 @@ public class Lower extends TreeTranslator {
boolean qualifiedSuperAccess =
tree.selected.hasTag(SELECT) &&
TreeInfo.name(tree.selected) == names._super &&
!types.isDirectSuperInterface(((JCFieldAccess)tree.selected).selected.type, currentClass);
!types.isDirectSuperInterface(((JCFieldAccess)tree.selected).selected.type.tsym, currentClass);
tree.selected = translate(tree.selected);
if (tree.name == names._class) {
result = classOf(tree.selected);
}
else if (tree.name == names._super &&
types.isDirectSuperInterface(tree.selected.type, currentClass)) {
types.isDirectSuperInterface(tree.selected.type.tsym, currentClass)) {
//default super call!! Not a classic qualified super call
TypeSymbol supSym = tree.selected.type.tsym;
Assert.checkNonNull(types.asSuper(currentClass.type, supSym));

View file

@ -427,6 +427,60 @@ public class Resolve {
return c != null;
}
/**
* Performs a recursive scan of a type looking for accessibility problems
* from current attribution environment
*/
void checkAccessibleType(Env<AttrContext> env, Type t) {
accessibilityChecker.visit(t, env);
}
/**
* Accessibility type-visitor
*/
Types.SimpleVisitor<Void, Env<AttrContext>> accessibilityChecker =
new Types.SimpleVisitor<Void, Env<AttrContext>>() {
void visit(List<Type> ts, Env<AttrContext> env) {
for (Type t : ts) {
visit(t, env);
}
}
public Void visitType(Type t, Env<AttrContext> env) {
return null;
}
@Override
public Void visitArrayType(ArrayType t, Env<AttrContext> env) {
visit(t.elemtype, env);
return null;
}
@Override
public Void visitClassType(ClassType t, Env<AttrContext> env) {
visit(t.getTypeArguments(), env);
if (!isAccessible(env, t, true)) {
accessBase(new AccessError(t.tsym), env.tree.pos(), env.enclClass.sym, t, t.tsym.name, true);
}
return null;
}
@Override
public Void visitWildcardType(WildcardType t, Env<AttrContext> env) {
visit(t.type, env);
return null;
}
@Override
public Void visitMethodType(MethodType t, Env<AttrContext> env) {
visit(t.getParameterTypes(), env);
visit(t.getReturnType(), env);
visit(t.getThrownTypes(), env);
return null;
}
};
/** Try to instantiate the type of a method so that it fits
* given type arguments and argument types. If succesful, return
* the method's instantiated type, else return null.
@ -750,10 +804,6 @@ public class Resolve {
public boolean compatible(Type found, Type req, Warner warn) {
return types.isSubtypeUnchecked(found, inferenceContext.asFree(req, types), warn);
}
public boolean allowBoxing() {
return false;
}
}
/**
@ -770,10 +820,6 @@ public class Resolve {
public boolean compatible(Type found, Type req, Warner warn) {
return types.isConvertible(found, inferenceContext.asFree(req, types), warn);
}
public boolean allowBoxing() {
return true;
}
}
/**
@ -792,7 +838,7 @@ public class Resolve {
DeferredAttr.DeferredAttrContext deferredAttrContext;
public MethodResultInfo(Type pt, MethodCheckContext checkContext, DeferredAttr.DeferredAttrContext deferredAttrContext) {
public MethodResultInfo(Type pt, CheckContext checkContext, DeferredAttr.DeferredAttrContext deferredAttrContext) {
attr.super(VAL, pt, checkContext);
this.deferredAttrContext = deferredAttrContext;
}
@ -809,7 +855,12 @@ public class Resolve {
@Override
protected MethodResultInfo dup(Type newPt) {
return new MethodResultInfo(newPt, (MethodCheckContext)checkContext, deferredAttrContext);
return new MethodResultInfo(newPt, checkContext, deferredAttrContext);
}
@Override
protected ResultInfo dup(CheckContext newContext) {
return new MethodResultInfo(pt, newContext, deferredAttrContext);
}
}
@ -1020,7 +1071,7 @@ public class Resolve {
Assert.check(sym.kind < AMBIGUOUS);
try {
Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes,
allowBoxing, useVarargs, Warner.noWarnings);
allowBoxing, useVarargs, types.noWarnings);
if (!operator)
currentResolutionContext.addApplicableCandidate(sym, mt);
} catch (InapplicableMethodException ex) {
@ -1921,28 +1972,31 @@ public class Resolve {
(typeargtypes == null || !Type.isErroneous(typeargtypes));
}
public List<Type> getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List<Type> argtypes) {
if (syms.operatorNames.contains(name)) {
return argtypes;
} else {
Symbol msym = errSym.kind == WRONG_MTH ?
((InapplicableSymbolError)errSym).errCandidate().sym : accessedSym;
return (syms.operatorNames.contains(name)) ?
argtypes :
Type.map(argtypes, new ResolveDeferredRecoveryMap(accessedSym));
}
List<Type> argtypes2 = Type.map(argtypes,
deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, msym, currentResolutionContext.step));
class ResolveDeferredRecoveryMap extends DeferredAttr.RecoveryDeferredTypeMap {
if (msym != accessedSym) {
//fixup deferred type caches - this 'hack' is required because the symbol
//returned by InapplicableSymbolError.access() will hide the candidate
//method symbol that can be used for lookups in the speculative cache,
//causing problems in Attr.checkId()
for (Type t : argtypes) {
if (t.hasTag(DEFERRED)) {
DeferredType dt = (DeferredType)t;
dt.speculativeCache.dupAllTo(msym, accessedSym);
public ResolveDeferredRecoveryMap(Symbol msym) {
deferredAttr.super(AttrMode.SPECULATIVE, msym, currentResolutionContext.step);
}
@Override
protected Type typeOf(DeferredType dt) {
Type res = super.typeOf(dt);
if (!res.isErroneous()) {
switch (TreeInfo.skipParens(dt.tree).getTag()) {
case LAMBDA:
case REFERENCE:
return dt;
case CONDEXPR:
return res == Type.recoveryType ?
dt : res;
}
}
}
return argtypes2;
return res;
}
}
};
@ -2069,7 +2123,6 @@ public class Resolve {
} else if (allowMethodHandles) {
MethodSymbol msym = (MethodSymbol)sym;
if (msym.isSignaturePolymorphic(types)) {
env.info.pendingResolutionPhase = BASIC;
return findPolymorphicSignatureInstance(env, sym, argtypes);
}
}
@ -2086,7 +2139,7 @@ public class Resolve {
* @param argtypes The required argument types
*/
Symbol findPolymorphicSignatureInstance(Env<AttrContext> env,
Symbol spMethod,
final Symbol spMethod,
List<Type> argtypes) {
Type mtype = infer.instantiatePolymorphicSignatureInstance(env,
(MethodSymbol)spMethod, currentResolutionContext, argtypes);
@ -2098,7 +2151,12 @@ public class Resolve {
// create the desired method
long flags = ABSTRACT | HYPOTHETICAL | spMethod.flags() & Flags.AccessFlags;
Symbol msym = new MethodSymbol(flags, spMethod.name, mtype, spMethod.owner);
Symbol msym = new MethodSymbol(flags, spMethod.name, mtype, spMethod.owner) {
@Override
public Symbol baseSymbol() {
return spMethod;
}
};
polymorphicSignatureScope.enter(msym);
return msym;
}
@ -2707,7 +2765,7 @@ public class Resolve {
}
if (allowDefaultMethods && c.isInterface() &&
name == names._super && !isStatic(env) &&
types.isDirectSuperInterface(c.type, env.enclClass.sym)) {
types.isDirectSuperInterface(c, env.enclClass.sym)) {
//this might be a default super call if one of the superinterfaces is 'c'
for (Type t : pruneInterfaces(env.enclClass.type)) {
if (t.tsym == c) {
@ -3150,7 +3208,7 @@ public class Resolve {
"cant.apply.symbols",
name == names.init ? KindName.CONSTRUCTOR : absentKind(kind),
name == names.init ? site.tsym.name : name,
argtypes);
methodArguments(argtypes));
return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(site));
} else {
return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind, pos,

View file

@ -133,7 +133,7 @@ public class TransTypes extends TreeTranslator {
JCExpression coerce(JCExpression tree, Type target) {
Type btarget = target.baseType();
if (tree.type.isPrimitive() == target.isPrimitive()) {
return types.isAssignable(tree.type, btarget, Warner.noWarnings)
return types.isAssignable(tree.type, btarget, types.noWarnings)
? tree
: cast(tree, btarget);
}

View file

@ -941,18 +941,6 @@ public class ClassReader implements Completer {
new AttributeReader(names.Code, V45_3, MEMBER_ATTRIBUTE) {
protected void read(Symbol sym, int attrLen) {
if (currentOwner.isInterface() &&
(sym.flags_field & ABSTRACT) == 0 && !name.equals(names.clinit)) {
if (majorVersion > Target.JDK1_8.majorVersion ||
//todo replace with Target.Version when available
(majorVersion == Target.JDK1_8.majorVersion && minorVersion >= Target.JDK1_8.minorVersion)) {
currentOwner.flags_field |= DEFAULT;
sym.flags_field |= DEFAULT | ABSTRACT;
} else {
//protect against ill-formed classfiles
throw new CompletionFailure(currentOwner, "default method found in pre JDK 8 classfile");
}
}
if (readAllOfClassFile || saveParameterNames)
((MethodSymbol)sym).code = readCode(sym);
else
@ -1753,6 +1741,17 @@ public class ClassReader implements Completer {
long flags = adjustMethodFlags(nextChar());
Name name = readName(nextChar());
Type type = readType(nextChar());
if (currentOwner.isInterface() &&
(flags & ABSTRACT) == 0 && !name.equals(names.clinit)) {
if (majorVersion > Target.JDK1_8.majorVersion ||
(majorVersion == Target.JDK1_8.majorVersion && minorVersion >= Target.JDK1_8.minorVersion)) {
currentOwner.flags_field |= DEFAULT;
flags |= DEFAULT | ABSTRACT;
} else {
//protect against ill-formed classfiles
throw new CompletionFailure(currentOwner, "default method found in pre JDK 8 classfile");
}
}
if (name == names.init && currentOwner.hasOuterInstance()) {
// Sometimes anonymous classes don't have an outer
// instance, however, there is no reliable way to tell so

View file

@ -95,10 +95,7 @@ public class Pool {
* package. Return the object's index in the pool.
*/
public int put(Object value) {
if (value instanceof MethodSymbol)
value = new Method((MethodSymbol)value);
else if (value instanceof VarSymbol)
value = new Variable((VarSymbol)value);
value = makePoolValue(value);
// assert !(value instanceof Type.TypeVar);
Integer index = indices.get(value);
if (index == null) {
@ -115,6 +112,18 @@ public class Pool {
return index.intValue();
}
Object makePoolValue(Object o) {
if (o instanceof DynamicMethodSymbol) {
return new DynamicMethod((DynamicMethodSymbol)o);
} else if (o instanceof MethodSymbol) {
return new Method((MethodSymbol)o);
} else if (o instanceof VarSymbol) {
return new Variable((VarSymbol)o);
} else {
return o;
}
}
/** Return the given object's index in the pool,
* or -1 if object is not in there.
*/
@ -145,6 +154,36 @@ public class Pool {
}
}
static class DynamicMethod extends Method {
DynamicMethod(DynamicMethodSymbol m) {
super(m);
}
@Override
public boolean equals(Object other) {
if (!super.equals(other)) return false;
if (!(other instanceof DynamicMethod)) return false;
DynamicMethodSymbol dm1 = (DynamicMethodSymbol)m;
DynamicMethodSymbol dm2 = (DynamicMethodSymbol)((DynamicMethod)other).m;
return dm1.bsm == dm2.bsm &&
dm1.bsmKind == dm2.bsmKind &&
Arrays.equals(dm1.staticArgs, dm2.staticArgs);
}
@Override
public int hashCode() {
int hash = super.hashCode();
DynamicMethodSymbol dm = (DynamicMethodSymbol)m;
hash += dm.bsmKind * 7 +
dm.bsm.hashCode() * 11;
for (int i = 0; i < dm.staticArgs.length; i++) {
hash += (dm.staticArgs[i].hashCode() * 23);
}
return hash;
}
}
static class Variable extends DelegatedSymbol {
VarSymbol v;
Variable(VarSymbol v) {

View file

@ -121,12 +121,9 @@ public class JavacParser implements Parser {
this.allowDiamond = source.allowDiamond();
this.allowMulticatch = source.allowMulticatch();
this.allowStringFolding = fac.options.getBoolean("allowStringFolding", true);
this.allowLambda = source.allowLambda() &&
fac.options.isSet("allowLambda"); //pre-lambda guard
this.allowMethodReferences = source.allowMethodReferences() &&
fac.options.isSet("allowMethodReferences"); //pre-lambda guard
this.allowDefaultMethods = source.allowDefaultMethods() &&
fac.options.isSet("allowDefaultMethods"); //pre-lambda guard
this.allowLambda = source.allowLambda();
this.allowMethodReferences = source.allowMethodReferences();
this.allowDefaultMethods = source.allowDefaultMethods();
this.keepDocComments = keepDocComments;
docComments = newDocCommentTable(keepDocComments, fac);
this.keepLineMap = keepLineMap;

View file

@ -170,19 +170,6 @@ compiler.misc.cant.apply.symbol=\
compiler.misc.cant.apply.symbols=\
no suitable {0} found for {1}({2})
# 0: type
compiler.err.cant.access.arg.type.in.functional.desc=\
cannot access parameter type {0} in target functional descriptor
# 0: type
compiler.err.cant.access.return.in.functional.desc=\
cannot access return type {0} in target functional descriptor
# 0: type
compiler.err.cant.access.thrown.in.functional.desc=\
cannot access thrown type {0} in target functional descriptor
# 0: symbol kind, 1: symbol
compiler.misc.no.abstracts=\
no abstract method found in {0} {1}
@ -257,9 +244,6 @@ compiler.err.cant.inherit.from.final=\
compiler.err.cant.ref.before.ctor.called=\
cannot reference {0} before supertype constructor has been called
compiler.err.cant.ret.val.from.meth.decl.void=\
cannot return a value from method whose result type is void
compiler.err.cant.select.static.class.from.param.type=\
cannot select a static class from a parameterized type
@ -661,8 +645,8 @@ compiler.err.missing.ret.stmt=\
compiler.misc.missing.ret.val=\
missing return value
compiler.err.missing.ret.val=\
missing return value
compiler.misc.unexpected.ret.val=\
unexpected return value
# 0: set of modifier
compiler.err.mod.not.allowed.here=\
@ -708,6 +692,9 @@ compiler.err.neither.conditional.subtype=\
compiler.misc.incompatible.type.in.conditional=\
bad type in conditional expression; {0}
compiler.misc.conditional.target.cant.be.void=\
target-type for conditional expression cannot be void
# 0: type
compiler.misc.incompatible.ret.type.in.lambda=\
bad return type in lambda expression\n\
@ -960,7 +947,7 @@ compiler.err.illegal.default.super.call=\
# 0: symbol, 1: type
compiler.misc.overridden.default=\
method {0} is overridden in {2}
method {0} is overridden in {1}
# 0: symbol, 1: symbol
compiler.misc.redundant.supertype=\

View file

@ -1110,7 +1110,7 @@ public class Pretty extends JCTree.Visitor {
public void visitReference(JCMemberReference tree) {
try {
printExpr(tree.expr);
print("#");
print("::");
if (tree.typeargs != null) {
print("<");
printExprs(tree.typeargs);

View file

@ -525,7 +525,8 @@ public class RichDiagnosticFormatter extends
bound = ((ErrorType)bound).getOriginalType();
//retrieve the bound list - if the type variable
//has not been attributed the bound is not set
List<Type> bounds = bound != null ?
List<Type> bounds = (bound != null) &&
(bound.hasTag(CLASS) || bound.hasTag(TYPEVAR)) ?
types.getBounds(t) :
List.<Type>nil();

View file

@ -39,7 +39,6 @@ import java.util.EnumSet;
* deletion without notice.</b>
*/
public class Warner {
public static final Warner noWarnings = new Warner();
private DiagnosticPosition pos = null;
protected boolean warned = false;

View file

@ -27,8 +27,8 @@
* @summary Conditional operator applies assignment conversion
* @author Tim Hanson, BEA
*
* @compile -XDallowPoly Conditional.java
* @compile/fail Conditional.java
* @compile Conditional.java
* @compile/fail -source 7 Conditional.java
*/
import java.util.*;

View file

@ -25,7 +25,7 @@
* @test
* @summary check that default methods don't cause ClassReader to complete classes recursively
* @author Maurizio Cimadamore
* @compile -XDallowDefaultMethods pkg/Foo.java
* @compile pkg/Foo.java
* @compile ClassReaderTest.java
*/

View file

@ -1,7 +1,7 @@
/*
* @test /nodynamiccopyright/
* @summary negative test for ambiguous defaults
* @compile/fail/ref=Neg01.out -XDallowDefaultMethods -XDrawDiagnostics Neg01.java
* @compile/fail/ref=Neg01.out -XDrawDiagnostics Neg01.java
*/
class Neg01 {

View file

@ -1,7 +1,7 @@
/*
* @test /nodynamiccopyright/
* @summary check that ill-formed MI hierarchies do not compile
* @compile/fail/ref=Neg02.out -XDallowDefaultMethods -XDrawDiagnostics Neg02.java
* @compile/fail/ref=Neg02.out -XDrawDiagnostics Neg02.java
*/
class Neg02 {

View file

@ -1,7 +1,7 @@
/*
* @test /nodynamiccopyright/
* @summary check that re-abstraction works properly
* @compile/fail/ref=Neg03.out -XDallowDefaultMethods -XDrawDiagnostics Neg03.java
* @compile/fail/ref=Neg03.out -XDrawDiagnostics Neg03.java
*/
class Neg03 {

View file

@ -1,7 +1,7 @@
/*
* @test /nodynamiccopyright/
* @summary check that default method must have most specific return type
* @compile/fail/ref=Neg04.out -XDallowDefaultMethods -XDrawDiagnostics Neg04.java
* @compile/fail/ref=Neg04.out -XDrawDiagnostics Neg04.java
*/
class Neg04 {

View file

@ -1,7 +1,7 @@
/*
* @test /nodynamiccopyright/
* @summary check that abstract methods are compatible with inherited defaults
* @compile/fail/ref=Neg05.out -XDallowDefaultMethods -XDrawDiagnostics Neg05.java
* @compile/fail/ref=Neg05.out -XDrawDiagnostics Neg05.java
*/
class Neg05 {

View file

@ -1,7 +1,7 @@
/*
* @test /nodynamiccopyright/
* @summary flow analysis is not run on inlined default bodies
* @compile/fail/ref=Neg06.out -XDallowDefaultMethods -XDrawDiagnostics Neg06.java
* @compile/fail/ref=Neg06.out -XDrawDiagnostics Neg06.java
*/
class Neg06 {

View file

@ -1,7 +1,7 @@
/*
* @test /nodynamiccopyright/
* @summary check that default overrides are properly type-checked
* @compile/fail/ref=Neg07.out -XDallowDefaultMethods -XDrawDiagnostics Neg07.java
* @compile/fail/ref=Neg07.out -XDrawDiagnostics Neg07.java
*/
class Neg07 {

View file

@ -1,7 +1,7 @@
/*
* @test /nodynamiccopyright/
* @summary check that default overrides are properly type-checked
* @compile/fail/ref=Neg08.out -XDallowDefaultMethods -XDrawDiagnostics Neg08.java
* @compile/fail/ref=Neg08.out -XDrawDiagnostics Neg08.java
*/
class Neg08 {
interface I {

View file

@ -1,7 +1,7 @@
/*
* @test /nodynamiccopyright/
* @summary check that default overrides are properly type-checked
* @compile/fail/ref=Neg09.out -Werror -Xlint:unchecked -XDallowDefaultMethods -XDrawDiagnostics Neg09.java
* @compile/fail/ref=Neg09.out -Werror -Xlint:unchecked -XDrawDiagnostics Neg09.java
*/
import java.util.List;

View file

@ -1,7 +1,7 @@
/*
* @test /nodynamiccopyright/
* @summary check that default overrides are properly type-checked
* @compile/fail/ref=Neg10.out -Werror -Xlint:unchecked -XDallowDefaultMethods -XDrawDiagnostics Neg10.java
* @compile/fail/ref=Neg10.out -Werror -Xlint:unchecked -XDrawDiagnostics Neg10.java
*/
class Neg10 {
interface I<X extends Exception> {

View file

@ -1,7 +1,7 @@
/*
* @test /nodynamiccopyright/
* @summary check that default overrides are properly type-checked
* @compile/fail/ref=Neg11.out -XDallowDefaultMethods -XDrawDiagnostics Neg11.java
* @compile/fail/ref=Neg11.out -XDrawDiagnostics Neg11.java
*/
class Neg11 {
interface I {

View file

@ -1,7 +1,7 @@
/*
* @test /nodynamiccopyright/
* @summary check that abstract methods are discarded in overload resolution diags
* @compile/fail/ref=Neg12.out -XDallowDefaultMethods -XDrawDiagnostics Neg12.java
* @compile/fail/ref=Neg12.out -XDrawDiagnostics Neg12.java
*/
class Neg12 {

View file

@ -1,4 +1,4 @@
Neg12.java:21:12: compiler.err.does.not.override.abstract: Neg12.D, m(java.lang.String), Neg12.I2
Neg12.java:24:10: compiler.err.cant.apply.symbols: kindname.method, m, ,{(compiler.misc.inapplicable.method: kindname.method, Neg12.I1, m(java.lang.String), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, Neg12.B, m(java.lang.Integer), (compiler.misc.arg.length.mismatch))}
Neg12.java:24:10: compiler.err.cant.apply.symbols: kindname.method, m, compiler.misc.no.args,{(compiler.misc.inapplicable.method: kindname.method, Neg12.I1, m(java.lang.String), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, Neg12.B, m(java.lang.Integer), (compiler.misc.arg.length.mismatch))}
Neg12.java:25:10: compiler.err.cant.apply.symbol: kindname.method, m, java.lang.Integer, compiler.misc.no.args, kindname.class, Neg12.B, (compiler.misc.arg.length.mismatch)
3 errors

View file

@ -1,7 +1,7 @@
/*
* @test /nodynamiccopyright/
* @summary check that default method overriding object members are flagged as error
* @compile/fail/ref=Neg13.out -XDallowDefaultMethods -XDrawDiagnostics Neg13.java
* @compile/fail/ref=Neg13.out -XDrawDiagnostics Neg13.java
*/
interface Neg13 {
default protected Object clone() { return null; } //protected not allowed here

View file

@ -1,7 +1,7 @@
/*
* @test /nodynamiccopyright/
* @summary check that a class cannot have two sibling interfaces with a default and abstract method
* @compile/fail/ref=Neg14.out -XDallowDefaultMethods -XDrawDiagnostics Neg14.java
* @compile/fail/ref=Neg14.out -XDrawDiagnostics Neg14.java
*/
class Neg14 {
interface IA { int m(); }

View file

@ -1,7 +1,7 @@
/*
* @test /nodynamiccopyright/
* @summary check that level skipping in default super calls is correctly rejected
* @compile/fail/ref=Neg15.out -XDallowDefaultMethods -XDrawDiagnostics Neg15.java
* @compile/fail/ref=Neg15.out -XDrawDiagnostics Neg15.java
*/
class Neg15 {
interface I { default void m() { } }

View file

@ -1,7 +1,7 @@
/*
* @test /nodynamiccopyright/
* @summary check that level skipping in default super calls is correctly rejected
* @compile/fail/ref=Neg16.out -XDallowDefaultMethods -XDrawDiagnostics Neg16.java
* @compile/fail/ref=Neg16.out -XDrawDiagnostics Neg16.java
*/
class Neg16 {
interface I { default void m() { } }

View file

@ -24,14 +24,12 @@
/*
* @test
* @summary basic test for default methods
* @ignore awaits lambda support
* @author Maurizio Cimadamore
* @compile -XDallowLambda -XDallowPoly -XDallowDefaultMethods Pos01.java
*/
import java.util.*;
class Pos01 {
public class Pos01 {
interface Mapper<T> {
T map(T in);

View file

@ -25,7 +25,7 @@
* @test
* @summary test for explicit resolution of ambiguous default methods
* @author Maurizio Cimadamore
* @compile -XDallowDefaultMethods Pos02.java
* @compile Pos02.java
*/
class Pos02 {

View file

@ -25,7 +25,7 @@
* @test
* @summary test for overriding with default method
* @author Maurizio Cimadamore
* @compile -XDallowDefaultMethods Pos04.java
* @compile Pos04.java
*/
class Pos04 {

View file

@ -25,7 +25,7 @@
* @test
* @summary check that indirectly inherited default methods are discovered during resolution
* @author Maurizio Cimadamore
* @compile -XDallowDefaultMethods Pos05.java
* @compile Pos05.java
*/
class Pos05 {

View file

@ -25,7 +25,7 @@
* @test
* @summary check that well-formed MI hierarchies behaves well w.r.t. method resolution (i.e. no ambiguities)
* @author Maurizio Cimadamore
* @compile -XDallowDefaultMethods Pos06.java
* @compile Pos06.java
*/
class Pos06 {

View file

@ -25,7 +25,7 @@
* @test
* @summary check that compilation order does not matter
* @author Maurizio Cimadamore
* @compile -XDallowDefaultMethods Pos07.java
* @compile Pos07.java
*/
class Pos07 {

View file

@ -25,7 +25,7 @@
* @test
* @summary check that common overrider solves default method conflicts
* @author Maurizio Cimadamore
* @compile -XDallowDefaultMethods Pos08.java
* @compile Pos08.java
*/
class Pos08 {

View file

@ -25,7 +25,7 @@
* @test
* @summary check that type-variables in generic extension decl can be accessed from default impl
* @author Maurizio Cimadamore
* @compile -XDallowDefaultMethods Pos10.java
* @compile Pos10.java
*/
class Pos10 {

View file

@ -25,7 +25,7 @@
* @test
* @summary complex test with conflict resolution via overriding
* @author Brian Goetz
* @compile -XDallowDefaultMethods Pos11.java
* @compile Pos11.java
*/
class Pos11 {

View file

@ -24,7 +24,7 @@
/*
* @test
* @summary check that 'this' can be used from within an extension method
* @compile -XDallowDefaultMethods Pos12.java
* @compile Pos12.java
*/
interface Pos12 {

View file

@ -24,7 +24,7 @@
/*
* @test
* @summary qualified 'this' inside default method causes StackOverflowException
* @compile -XDallowDefaultMethods Pos13.java
* @compile Pos13.java
*/
public class Pos13 {

View file

@ -24,7 +24,7 @@
/*
* @test
* @summary check that overload resolution selects most specific signature
* @compile -XDallowDefaultMethods Pos14.java
* @compile Pos14.java
*/
class Pos14 {

View file

@ -24,7 +24,7 @@
/*
* @test
* @summary check that overload resolution selects most specific signature
* @compile -XDallowDefaultMethods Pos15.java
* @compile Pos15.java
*/
class Pos15 {

View file

@ -24,7 +24,7 @@
/*
* @test
* @summary 'class wins' should not short-circuit overload resolution
* @compile -XDallowDefaultMethods Pos16.java
* @compile Pos16.java
*/
class Pos16 {

View file

@ -23,10 +23,7 @@
/*
* @test
* @ignore awaits for VM support
* @summary check that code attributed for default methods is correctly generated
* @compile -XDallowDefaultMethods TestDefaultBody.java
* @run main TestDefaultBody
*/
import com.sun.tools.classfile.AccessFlags;

View file

@ -25,8 +25,6 @@
* @test
* @ignore awaits for VM support
* @summary check that javac does not generate bridge methods for defaults
* @compile -XDallowDefaultMethods TestNoBridgeOnDefaults.java
* @run main TestNoBridgeOnDefaults
*/
import com.sun.tools.classfile.ClassFile;

View file

@ -82,7 +82,7 @@ public class FDTest {
void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
Arrays.asList("-XDallowDefaultMethods"), null, Arrays.asList(source));
null, null, Arrays.asList(source));
try {
ct.analyze();
} catch (Throwable ex) {

View file

@ -25,8 +25,8 @@
* @test
* @summary smoke test for separate compilation of default methods
* @author Maurizio Cimadamore
* @compile -XDallowDefaultMethods pkg1/A.java
* @compile -XDallowDefaultMethods Separate.java
* @compile pkg1/A.java
* @compile Separate.java
*/
import pkg1.A;

View file

@ -323,7 +323,7 @@ public class TestDefaultSuperCall {
void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
Arrays.asList("-XDallowDefaultMethods"), null, Arrays.asList(source));
null, null, Arrays.asList(source));
try {
ct.analyze();
} catch (Throwable ex) {

View file

@ -54,7 +54,7 @@ public class TestDefaultMethodsSyntax {
}
List<String> getOptions() {
return Arrays.asList("-XDallowDefaultMethods", "-source", versionString);
return Arrays.asList("-source", versionString);
}
}

View file

@ -24,7 +24,6 @@
// key: compiler.err.prob.found.req
// key: compiler.misc.cant.access.inner.cls.constr
// key: compiler.misc.invalid.mref
// options: -XDallowMethodReferences
class CantAccessInnerClsConstructor {

View file

@ -26,7 +26,6 @@
// key: compiler.misc.no.conforming.assignment.exists
// key: compiler.misc.cant.apply.symbol
// key: compiler.misc.invalid.mref
// options: -XDallowMethodReferences
class CantApplySymbolFragment {

View file

@ -28,7 +28,6 @@
// key: compiler.misc.inapplicable.method
// key: compiler.misc.cant.apply.symbols
// key: compiler.misc.invalid.mref
// options: -XDallowMethodReferences
class CantApplySymbolsFragment {

View file

@ -24,7 +24,6 @@
// key: compiler.err.cant.ref.non.effectively.final.var
// key: compiler.misc.inner.cls
// key: compiler.misc.lambda
// options: -XDallowLambda -XDallowEffectivelyFinalInInnerClasses
class CantRefNonEffectivelyFinalVar {
void test() {

View file

@ -24,7 +24,6 @@
// key: compiler.misc.cant.resolve.location.args
// key: compiler.misc.location
// key: compiler.err.invalid.mref
// options: -XDallowMethodReferences
class CantResolveLocationArgsFragment {

View file

@ -24,7 +24,6 @@
// key: compiler.misc.cant.resolve.location.args.params
// key: compiler.misc.location
// key: compiler.err.invalid.mref
// options: -XDallowMethodReferences
class CantResolveLocationArgsParamsFragment {

View file

@ -0,0 +1,37 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// key: compiler.err.prob.found.req
// key: compiler.misc.incompatible.ret.type.in.lambda
// key: compiler.misc.conditional.target.cant.be.void
class ConditionalTargetCantBeVoid {
interface SAM {
void m();
}
void test(boolean cond, Object o1, Object o2) {
SAM s = ()-> cond ? o1 : o2;
}
}

View file

@ -23,7 +23,6 @@
// key: compiler.err.cant.apply.symbol
// key: compiler.misc.cyclic.inference
// options: -XDallowLambda -XDallowPoly
class CyclicInference {
interface SAM<X> {

View file

@ -22,7 +22,6 @@
*/
// key: compiler.err.default.overrides.object.member
// options: -XDallowDefaultMethods
interface DefaultOverridesObjectMember {
default String toString() { return ""; }

View file

@ -24,7 +24,6 @@
// key: compiler.err.prob.found.req
// key: compiler.misc.not.a.functional.intf.1
// key: compiler.misc.incompatible.abstracts
// options: -XDallowLambda
class IncompatibleAbstracts {

View file

@ -23,7 +23,6 @@
// key: compiler.err.prob.found.req
// key: compiler.misc.incompatible.arg.types.in.lambda
// options: -XDallowLambda -XDallowPoly
class IncompatibleArgTypesInLambda {
interface SAM {

View file

@ -26,7 +26,6 @@
// key: compiler.misc.incompatible.descs.in.functional.intf
// key: compiler.misc.descriptor
// key: compiler.misc.descriptor.throws
// options: -XDallowLambda
class IncompatibleDescsInFunctionalIntf {
interface A {

View file

@ -24,7 +24,6 @@
// key: compiler.err.prob.found.req
// key: compiler.misc.inconvertible.types
// key: compiler.misc.incompatible.ret.type.in.lambda
// options: -XDallowLambda -XDallowPoly
class IncompatibleRetTypeInLambda {
interface SAM {

View file

@ -24,7 +24,6 @@
// key: compiler.err.prob.found.req
// key: compiler.misc.inconvertible.types
// key: compiler.misc.incompatible.ret.type.in.mref
// options: -XDallowMethodReferences -XDallowPoly
class IncompatibleRetTypeInMref {
interface SAM {

View file

@ -22,7 +22,6 @@
*/
// key: compiler.err.incompatible.thrown.types.in.lambda
// options: -XDallowLambda
class IncompatibleThrownTypesInLambda {
interface SAM {

View file

@ -22,7 +22,6 @@
*/
// key: compiler.err.incompatible.thrown.types.in.mref
// options: -XDallowMethodReferences
class IncompatibleThrownTypesInMref {
interface SAM {

View file

@ -24,7 +24,6 @@
// key: compiler.err.prob.found.req
// key: compiler.misc.incompatible.type.in.conditional
// key: compiler.misc.inconvertible.types
// options: -XDallowPoly
class IncompatibleTypesInConditional {

View file

@ -23,7 +23,6 @@
// key: compiler.err.prob.found.req
// key: compiler.misc.invalid.generic.desc.in.functional.intf
// options: -XDallowLambda
class InvalidGenericDescInFunctionalIntf {

View file

@ -22,6 +22,7 @@
*/
// key: compiler.err.local.var.accessed.from.icls.needs.final
// options: -Xlint:-options -source 7
class LocalVarNeedsFinal {
Runnable m() {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.missing.ret.val
// key: compiler.err.prob.found.req
// key: compiler.misc.missing.ret.val
class MissingReturnValue {
int m() {

View file

@ -24,7 +24,6 @@
// key: compiler.err.prob.found.req
// key: compiler.misc.incompatible.ret.type.in.lambda
// key: compiler.misc.missing.ret.val
// options: -XDallowLambda
class MissingReturnValueFragment {
interface SAM {

View file

@ -24,7 +24,6 @@
// key: compiler.err.prob.found.req
// key: compiler.misc.not.a.functional.intf.1
// key: compiler.misc.no.abstracts
// options: -XDallowLambda
class NoAbstracts {

View file

@ -23,7 +23,6 @@
// key: compiler.err.prob.found.req
// key: compiler.misc.no.suitable.functional.intf.inst
// options: -XDallowLambda
class NoSuitableFunctionalIntfInst {

View file

@ -24,7 +24,6 @@
// key: compiler.err.prob.found.req
// key: compiler.misc.non-static.cant.be.ref
// key: compiler.misc.invalid.mref
// options: -XDallowMethodReferences
class NonStaticCantBeRefFragment {

View file

@ -23,7 +23,6 @@
// key: compiler.err.prob.found.req
// key: compiler.misc.not.a.functional.intf
// options: -XDallowLambda
class NotAFunctionalIntf {

View file

@ -24,7 +24,6 @@
// key: compiler.err.prob.found.req
// key: compiler.misc.not.def.access.class.intf.cant.access
// key: compiler.misc.invalid.mref
// options: -XDallowMethodReferences
class NotDefAccessClassIntfCantAccessFragment {

View file

@ -23,7 +23,6 @@
// key: compiler.err.illegal.default.super.call
// key: compiler.misc.overridden.default
// options: -XDallowDefaultMethods
class OverriddenDefault {
interface I { default void m() { } }

View file

@ -22,7 +22,7 @@
*/
// key: compiler.note.potential.lambda.found
// options: -XDallowLambda -XDidentifyLambdaCandidate=true
// options: -XDidentifyLambdaCandidate=true
class PotentialLambdaFound {

View file

@ -23,7 +23,6 @@
// key: compiler.err.illegal.default.super.call
// key: compiler.misc.redundant.supertype
// options: -XDallowDefaultMethods
class RedundantSupertype {
interface I { default void m() { } }

View file

@ -24,7 +24,6 @@
// key: compiler.err.prob.found.req
// key: compiler.misc.ref.ambiguous
// key: compiler.misc.invalid.mref
// options: -XDallowMethodReferences
class RefAmbiguousFragment {

View file

@ -22,7 +22,6 @@
*/
// key: compiler.err.types.incompatible.abstract.default
// options: -XDallowDefaultMethods
class TypesIncompatibleAbstractDefault {
interface A {

View file

@ -22,7 +22,6 @@
*/
// key: compiler.err.types.incompatible.unrelated.defaults
// options: -XDallowDefaultMethods
class TypesIncompatibleUnrelatedDefaults {
interface A {

View file

@ -22,7 +22,6 @@
*/
// key: compiler.err.unexpected.lambda
// options: -XDallowLambda
class UnexpectedLambda {
{ (()-> { })++; }

View file

@ -22,7 +22,6 @@
*/
// key: compiler.err.unexpected.mref
// options: -XDallowMethodReferences
class UnexpectedLambda {
{ (Foo::bar)++; }

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,9 +21,10 @@
* questions.
*/
// key: compiler.err.cant.ret.val.from.meth.decl.void
// key: compiler.err.prob.found.req
// key: compiler.misc.unexpected.ret.val
class CantReturnValueForVoid {
class UnexpectedReturnValue {
void m() {
return 3;
}

View file

@ -27,7 +27,7 @@
*
* @summary Invalid compiler error on covariant overriding methods with the same erasure
* @compile -source 7 T7022054pos1.java
* @compile/fail -XDstrictMethodClashCheck T7022054pos1.java
* @compile/fail/ref=T7022054pos1.out -XDrawDiagnostics T7022054pos1.java
*
*/

View file

@ -0,0 +1,2 @@
T7022054pos1.java:39:25: compiler.err.name.clash.same.erasure.no.override: <X>m(java.lang.String), T7022054pos1.B, m(java.lang.String), T7022054pos1.A, <X>m(java.lang.String), T7022054pos1.B
1 error

View file

@ -27,7 +27,7 @@
*
* @summary Invalid compiler error on covariant overriding methods with the same erasure
* @compile -source 7 T7022054pos2.java
* @compile/fail -XDstrictMethodClashCheck T7022054pos2.java
* @compile/fail/ref=T7022054pos2.out -XDrawDiagnostics T7022054pos2.java
*/
class T7022054pos2 {

View file

@ -0,0 +1,2 @@
T7022054pos2.java:38:32: compiler.err.name.clash.same.erasure.no.hide: <X>m(java.lang.String), T7022054pos2.B, m(java.lang.String), T7022054pos2.A
1 error

View file

@ -0,0 +1,30 @@
/*
* @test /nodynamiccopyright/
* @bug 8003280
* @summary Add lambda tests
* check that non-static variables are not accessible from static lambdas
* @author Maurizio Cimadamore
* @compile/fail/ref=BadAccess.out -XDrawDiagnostics BadAccess.java
*/
public class BadAccess {
int i;
static int I;
interface SAM {
int m();
}
static void test1() {
int l = 0; //effectively final
final int L = 0;
SAM s = ()-> i + I + l + L;
}
void test2() {
int l = 0; //effectively final
final int L = 0;
SAM s = ()-> i + I + l + L;
}
}

View file

@ -0,0 +1,2 @@
BadAccess.java:22:22: compiler.err.non-static.cant.be.ref: kindname.variable, i
1 error

View file

@ -0,0 +1,31 @@
/*
* @test /nodynamiccopyright/
* @bug 8003280
* @summary Add lambda tests
* check lambda can access only effectively-final locals
* @author Maurizio Cimadamore
* @compile/fail/ref=BadAccess02.out -XDrawDiagnostics BadAccess02.java
*/
public class BadAccess02 {
interface SAM {
int m(int h);
}
static void test1() {
int l = 0; //effectively final
int j = 0; //non-effectively final
j = 2;
final int L = 0;
SAM s = (int h) -> { int k = 0; return h + j + l + L; };
}
void test2() {
int l = 0; //effectively final
int j = 0; //non-effectively final
j = 2;
final int L = 0;
SAM s = (int h) -> { int k = 0; return h + k + j + l + L; };
}
}

View file

@ -0,0 +1,3 @@
BadAccess02.java:21:52: compiler.err.cant.ref.non.effectively.final.var: j, (compiler.misc.lambda)
BadAccess02.java:29:56: compiler.err.cant.ref.non.effectively.final.var: j, (compiler.misc.lambda)
2 errors

Some files were not shown because too many files have changed in this diff Show more