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&NATIVE) != 0) flags.add(Flag.NATIVE);
if ((mask&INTERFACE) != 0) flags.add(Flag.INTERFACE); if ((mask&INTERFACE) != 0) flags.add(Flag.INTERFACE);
if ((mask&ABSTRACT) != 0) flags.add(Flag.ABSTRACT); 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&STRICTFP) != 0) flags.add(Flag.STRICTFP);
if ((mask&BRIDGE) != 0) flags.add(Flag.BRIDGE); if ((mask&BRIDGE) != 0) flags.add(Flag.BRIDGE);
if ((mask&SYNTHETIC) != 0) flags.add(Flag.SYNTHETIC); 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 * Flag that marks class as auxiliary, ie a non-public class following
* the public class in a source file, that could block implicit compilation. * 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. /** Modifier masks.
*/ */

View file

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

View file

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

View file

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

View file

@ -120,8 +120,7 @@ public class Check {
allowCovariantReturns = source.allowCovariantReturns(); allowCovariantReturns = source.allowCovariantReturns();
allowSimplifiedVarargs = source.allowSimplifiedVarargs(); allowSimplifiedVarargs = source.allowSimplifiedVarargs();
allowDefaultMethods = source.allowDefaultMethods(); allowDefaultMethods = source.allowDefaultMethods();
allowStrictMethodClashCheck = source.allowStrictMethodClashCheck() && allowStrictMethodClashCheck = source.allowStrictMethodClashCheck();
options.isSet("strictMethodClashCheck"); //pre-lambda guard
complexInference = options.isSet("complexinference"); complexInference = options.isSet("complexinference");
warnOnSyntheticConflicts = options.isSet("warnOnSyntheticConflicts"); warnOnSyntheticConflicts = options.isSet("warnOnSyntheticConflicts");
suppressAbortOnBadClassFile = options.isSet("suppressAbortOnBadClassFile"); suppressAbortOnBadClassFile = options.isSet("suppressAbortOnBadClassFile");
@ -451,8 +450,6 @@ public class Check {
public Infer.InferenceContext inferenceContext(); public Infer.InferenceContext inferenceContext();
public DeferredAttr.DeferredAttrContext deferredAttrContext(); public DeferredAttr.DeferredAttrContext deferredAttrContext();
public boolean allowBoxing();
} }
/** /**
@ -487,10 +484,6 @@ public class Check {
public DeferredAttrContext deferredAttrContext() { public DeferredAttrContext deferredAttrContext() {
return enclosingContext.deferredAttrContext(); return enclosingContext.deferredAttrContext();
} }
public boolean allowBoxing() {
return enclosingContext.allowBoxing();
}
} }
/** /**
@ -515,10 +508,6 @@ public class Check {
public DeferredAttrContext deferredAttrContext() { public DeferredAttrContext deferredAttrContext() {
return deferredAttr.emptyDeferredAttrContext; return deferredAttr.emptyDeferredAttrContext;
} }
public boolean allowBoxing() {
return true;
}
}; };
/** Check that a given type is assignable to a given proto-type. /** Check that a given type is assignable to a given proto-type.
@ -625,7 +614,7 @@ public class Check {
a = types.upperBound(a); a = types.upperBound(a);
return types.isSubtype(a, bound); return types.isSubtype(a, bound);
} else if (a.isExtendsBound()) { } 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()) { } else if (a.isSuperBound()) {
return !types.notSoftSubtype(types.lowerBound(a), bound); return !types.notSoftSubtype(types.lowerBound(a), bound);
} }
@ -909,19 +898,21 @@ public class Check {
"unchecked.generic.array.creation", "unchecked.generic.array.creation",
argtype); argtype);
} }
Type elemtype = types.elemtype(argtype); if (!((MethodSymbol)sym.baseSymbol()).isSignaturePolymorphic(types)) {
switch (tree.getTag()) { Type elemtype = types.elemtype(argtype);
case APPLY: switch (tree.getTag()) {
((JCMethodInvocation) tree).varargsElement = elemtype; case APPLY:
break; ((JCMethodInvocation) tree).varargsElement = elemtype;
case NEWCLASS: break;
((JCNewClass) tree).varargsElement = elemtype; case NEWCLASS:
break; ((JCNewClass) tree).varargsElement = elemtype;
case REFERENCE: break;
((JCMemberReference) tree).varargsElement = elemtype; case REFERENCE:
break; ((JCMemberReference) tree).varargsElement = elemtype;
default: break;
throw new AssertionError(""+tree); default:
throw new AssertionError(""+tree);
}
} }
} }
return owntype; return owntype;
@ -937,65 +928,6 @@ public class Check {
return; 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 * Check that type 't' is a valid instantiation of a generic class
* (see JLS 4.5) * (see JLS 4.5)
@ -1919,8 +1851,8 @@ public class Check {
types.isSameType(rt1, rt2) || types.isSameType(rt1, rt2) ||
!rt1.isPrimitiveOrVoid() && !rt1.isPrimitiveOrVoid() &&
!rt2.isPrimitiveOrVoid() && !rt2.isPrimitiveOrVoid() &&
(types.covariantReturnType(rt1, rt2, Warner.noWarnings) || (types.covariantReturnType(rt1, rt2, types.noWarnings) ||
types.covariantReturnType(rt2, rt1, Warner.noWarnings)) || types.covariantReturnType(rt2, rt1, types.noWarnings)) ||
checkCommonOverriderIn(s1,s2,site); checkCommonOverriderIn(s1,s2,site);
if (!compat) { if (!compat) {
log.error(pos, "types.incompatible.diff.ret", log.error(pos, "types.incompatible.diff.ret",
@ -1965,8 +1897,8 @@ public class Check {
boolean compat = boolean compat =
!rt13.isPrimitiveOrVoid() && !rt13.isPrimitiveOrVoid() &&
!rt23.isPrimitiveOrVoid() && !rt23.isPrimitiveOrVoid() &&
(types.covariantReturnType(rt13, rt1, Warner.noWarnings) && (types.covariantReturnType(rt13, rt1, types.noWarnings) &&
types.covariantReturnType(rt23, rt2, Warner.noWarnings)); types.covariantReturnType(rt23, rt2, types.noWarnings));
if (compat) if (compat)
return true; return true;
} }
@ -2280,19 +2212,33 @@ public class Check {
c.flags_field |= ACYCLIC; 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 /** Check that all methods which implement some
* method conform to the method they implement. * method conform to the method they implement.
* @param tree The class definition whose members are checked. * @param tree The class definition whose members are checked.
*/ */
void checkImplementations(JCClassDecl tree) { void checkImplementations(JCClassDecl tree) {
checkImplementations(tree, tree.sym); checkImplementations(tree, tree.sym, tree.sym);
} }
//where //where
/** Check that all methods which implement some /** Check that all methods which implement some
* method in `ic' conform to the method they implement. * method in `ic' conform to the method they implement.
*/ */
void checkImplementations(JCClassDecl tree, ClassSymbol ic) { void checkImplementations(JCTree tree, ClassSymbol origin, ClassSymbol ic) {
ClassSymbol origin = tree.sym;
for (List<Type> l = types.closure(ic.type); l.nonEmpty(); l = l.tail) { for (List<Type> l = types.closure(ic.type); l.nonEmpty(); l = l.tail) {
ClassSymbol lc = (ClassSymbol)l.head.tsym; ClassSymbol lc = (ClassSymbol)l.head.tsym;
if ((allowGenerics || origin != lc) && (lc.flags() & ABSTRACT) != 0) { 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 javax.tools.JavaFileObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
import java.util.Queue; import java.util.Queue;
import java.util.Set; import java.util.Set;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import static com.sun.tools.javac.code.TypeTag.DEFERRED; import static com.sun.tools.javac.code.TypeTag.*;
import static com.sun.tools.javac.code.TypeTag.NONE;
import static com.sun.tools.javac.tree.JCTree.Tag.*; 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 * Retrieve a speculative cache entry corresponding to given symbol
* and resolution phase * and resolution phase
@ -194,7 +180,7 @@ public class DeferredAttr extends JCTree.Visitor {
DeferredAttrContext deferredAttrContext = DeferredAttrContext deferredAttrContext =
resultInfo.checkContext.deferredAttrContext(); resultInfo.checkContext.deferredAttrContext();
Assert.check(deferredAttrContext != emptyDeferredAttrContext); Assert.check(deferredAttrContext != emptyDeferredAttrContext);
List<Type> stuckVars = stuckVars(tree, resultInfo); List<Type> stuckVars = stuckVars(tree, env, resultInfo);
if (stuckVars.nonEmpty()) { if (stuckVars.nonEmpty()) {
deferredAttrContext.addDeferredAttrNode(this, resultInfo, stuckVars); deferredAttrContext.addDeferredAttrNode(this, resultInfo, stuckVars);
return Type.noType; return Type.noType;
@ -275,6 +261,10 @@ public class DeferredAttr extends JCTree.Visitor {
@Override @Override
public void visitClassDef(JCClassDecl tree) { public void visitClassDef(JCClassDecl tree) {
ClassSymbol csym = tree.sym; 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); enter.typeEnvs.remove(csym);
chk.compiled.remove(csym.flatname); chk.compiled.remove(csym.flatname);
syms.classes.remove(csym.flatname); syms.classes.remove(csym.flatname);
@ -333,7 +323,7 @@ public class DeferredAttr extends JCTree.Visitor {
*/ */
void complete() { void complete() {
while (!deferredAttrNodes.isEmpty()) { while (!deferredAttrNodes.isEmpty()) {
Set<Type> stuckVars = new HashSet<Type>(); Set<Type> stuckVars = new LinkedHashSet<Type>();
boolean progress = false; boolean progress = false;
//scan a defensive copy of the node list - this is because a deferred //scan a defensive copy of the node list - this is because a deferred
//attribution round can add new nodes to the list //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 */ /** an empty deferred attribution context - all methods throw exceptions */
final DeferredAttrContext emptyDeferredAttrContext = final DeferredAttrContext emptyDeferredAttrContext =
new DeferredAttrContext(null, null, null, null) { new DeferredAttrContext(AttrMode.CHECK, null, MethodResolutionPhase.BOX, null) {
@Override @Override
void addDeferredAttrNode(DeferredType dt, ResultInfo ri, List<Type> stuckVars) { void addDeferredAttrNode(DeferredType dt, ResultInfo ri, List<Type> stuckVars) {
Assert.error("Empty deferred context!"); Assert.error("Empty deferred context!");
@ -471,13 +461,13 @@ public class DeferredAttr extends JCTree.Visitor {
public class RecoveryDeferredTypeMap extends DeferredTypeMap { public class RecoveryDeferredTypeMap extends DeferredTypeMap {
public RecoveryDeferredTypeMap(AttrMode mode, Symbol msym, MethodResolutionPhase phase) { public RecoveryDeferredTypeMap(AttrMode mode, Symbol msym, MethodResolutionPhase phase) {
super(mode, msym, phase); super(mode, msym, phase != null ? phase : MethodResolutionPhase.BOX);
} }
@Override @Override
protected Type typeOf(DeferredType dt) { protected Type typeOf(DeferredType dt) {
Type owntype = super.typeOf(dt); Type owntype = super.typeOf(dt);
return owntype.hasTag(NONE) ? return owntype == Type.noType ?
recover(dt) : owntype; recover(dt) : owntype;
} }
@ -495,16 +485,7 @@ public class DeferredAttr extends JCTree.Visitor {
*/ */
private Type recover(DeferredType dt) { private Type recover(DeferredType dt) {
dt.check(attr.new RecoveryInfo(deferredAttrContext)); dt.check(attr.new RecoveryInfo(deferredAttrContext));
switch (TreeInfo.skipParens(dt.tree).getTag()) { return super.apply(dt);
case LAMBDA:
case REFERENCE:
case CONDEXPR:
//propagate those deferred types to the
//diagnostic formatter
return dt;
default:
return super.apply(dt);
}
} }
} }
@ -513,11 +494,11 @@ public class DeferredAttr extends JCTree.Visitor {
* an AST node can be type-checked * an AST node can be type-checked
*/ */
@SuppressWarnings("fallthrough") @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()) { if (resultInfo.pt.hasTag(NONE) || resultInfo.pt.isErroneous()) {
return List.nil(); return List.nil();
} else { } else {
StuckChecker sc = new StuckChecker(resultInfo); StuckChecker sc = new StuckChecker(resultInfo, env);
sc.scan(tree); sc.scan(tree);
return List.from(sc.stuckVars); return List.from(sc.stuckVars);
} }
@ -534,7 +515,8 @@ public class DeferredAttr extends JCTree.Visitor {
Type pt; Type pt;
Filter<JCTree> treeFilter; Filter<JCTree> treeFilter;
Infer.InferenceContext inferenceContext; 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>() { final Filter<JCTree> argsFilter = new Filter<JCTree>() {
public boolean accepts(JCTree t) { 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.pt = resultInfo.pt;
this.inferenceContext = resultInfo.checkContext.inferenceContext(); this.inferenceContext = resultInfo.checkContext.inferenceContext();
this.treeFilter = argsFilter; this.treeFilter = argsFilter;
this.env = env;
} }
@Override @Override
@ -616,6 +599,7 @@ public class DeferredAttr extends JCTree.Visitor {
if (!types.isFunctionalInterface(pt.tsym)) { if (!types.isFunctionalInterface(pt.tsym)) {
return; return;
} }
Type descType = types.findDescriptorType(pt); Type descType = types.findDescriptorType(pt);
List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes()); List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes());
stuckVars.addAll(freeArgVars); stuckVars.addAll(freeArgVars);

View file

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

View file

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

View file

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

View file

@ -427,6 +427,60 @@ public class Resolve {
return c != null; 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 /** Try to instantiate the type of a method so that it fits
* given type arguments and argument types. If succesful, return * given type arguments and argument types. If succesful, return
* the method's instantiated type, else return null. * the method's instantiated type, else return null.
@ -750,10 +804,6 @@ public class Resolve {
public boolean compatible(Type found, Type req, Warner warn) { public boolean compatible(Type found, Type req, Warner warn) {
return types.isSubtypeUnchecked(found, inferenceContext.asFree(req, types), 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) { public boolean compatible(Type found, Type req, Warner warn) {
return types.isConvertible(found, inferenceContext.asFree(req, types), 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; 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); attr.super(VAL, pt, checkContext);
this.deferredAttrContext = deferredAttrContext; this.deferredAttrContext = deferredAttrContext;
} }
@ -809,7 +855,12 @@ public class Resolve {
@Override @Override
protected MethodResultInfo dup(Type newPt) { 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); Assert.check(sym.kind < AMBIGUOUS);
try { try {
Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes, Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes,
allowBoxing, useVarargs, Warner.noWarnings); allowBoxing, useVarargs, types.noWarnings);
if (!operator) if (!operator)
currentResolutionContext.addApplicableCandidate(sym, mt); currentResolutionContext.addApplicableCandidate(sym, mt);
} catch (InapplicableMethodException ex) { } catch (InapplicableMethodException ex) {
@ -1921,28 +1972,31 @@ public class Resolve {
(typeargtypes == null || !Type.isErroneous(typeargtypes)); (typeargtypes == null || !Type.isErroneous(typeargtypes));
} }
public List<Type> getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List<Type> argtypes) { public List<Type> getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List<Type> argtypes) {
if (syms.operatorNames.contains(name)) { return (syms.operatorNames.contains(name)) ?
return argtypes; argtypes :
} else { Type.map(argtypes, new ResolveDeferredRecoveryMap(accessedSym));
Symbol msym = errSym.kind == WRONG_MTH ? }
((InapplicableSymbolError)errSym).errCandidate().sym : accessedSym;
List<Type> argtypes2 = Type.map(argtypes, class ResolveDeferredRecoveryMap extends DeferredAttr.RecoveryDeferredTypeMap {
deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, msym, currentResolutionContext.step));
if (msym != accessedSym) { public ResolveDeferredRecoveryMap(Symbol msym) {
//fixup deferred type caches - this 'hack' is required because the symbol deferredAttr.super(AttrMode.SPECULATIVE, msym, currentResolutionContext.step);
//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() @Override
for (Type t : argtypes) { protected Type typeOf(DeferredType dt) {
if (t.hasTag(DEFERRED)) { Type res = super.typeOf(dt);
DeferredType dt = (DeferredType)t; if (!res.isErroneous()) {
dt.speculativeCache.dupAllTo(msym, accessedSym); 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) { } else if (allowMethodHandles) {
MethodSymbol msym = (MethodSymbol)sym; MethodSymbol msym = (MethodSymbol)sym;
if (msym.isSignaturePolymorphic(types)) { if (msym.isSignaturePolymorphic(types)) {
env.info.pendingResolutionPhase = BASIC;
return findPolymorphicSignatureInstance(env, sym, argtypes); return findPolymorphicSignatureInstance(env, sym, argtypes);
} }
} }
@ -2086,7 +2139,7 @@ public class Resolve {
* @param argtypes The required argument types * @param argtypes The required argument types
*/ */
Symbol findPolymorphicSignatureInstance(Env<AttrContext> env, Symbol findPolymorphicSignatureInstance(Env<AttrContext> env,
Symbol spMethod, final Symbol spMethod,
List<Type> argtypes) { List<Type> argtypes) {
Type mtype = infer.instantiatePolymorphicSignatureInstance(env, Type mtype = infer.instantiatePolymorphicSignatureInstance(env,
(MethodSymbol)spMethod, currentResolutionContext, argtypes); (MethodSymbol)spMethod, currentResolutionContext, argtypes);
@ -2098,7 +2151,12 @@ public class Resolve {
// create the desired method // create the desired method
long flags = ABSTRACT | HYPOTHETICAL | spMethod.flags() & Flags.AccessFlags; 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); polymorphicSignatureScope.enter(msym);
return msym; return msym;
} }
@ -2707,7 +2765,7 @@ public class Resolve {
} }
if (allowDefaultMethods && c.isInterface() && if (allowDefaultMethods && c.isInterface() &&
name == names._super && !isStatic(env) && 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' //this might be a default super call if one of the superinterfaces is 'c'
for (Type t : pruneInterfaces(env.enclClass.type)) { for (Type t : pruneInterfaces(env.enclClass.type)) {
if (t.tsym == c) { if (t.tsym == c) {
@ -3150,7 +3208,7 @@ public class Resolve {
"cant.apply.symbols", "cant.apply.symbols",
name == names.init ? KindName.CONSTRUCTOR : absentKind(kind), name == names.init ? KindName.CONSTRUCTOR : absentKind(kind),
name == names.init ? site.tsym.name : name, name == names.init ? site.tsym.name : name,
argtypes); methodArguments(argtypes));
return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(site)); return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(site));
} else { } else {
return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind, pos, 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) { JCExpression coerce(JCExpression tree, Type target) {
Type btarget = target.baseType(); Type btarget = target.baseType();
if (tree.type.isPrimitive() == target.isPrimitive()) { if (tree.type.isPrimitive() == target.isPrimitive()) {
return types.isAssignable(tree.type, btarget, Warner.noWarnings) return types.isAssignable(tree.type, btarget, types.noWarnings)
? tree ? tree
: cast(tree, btarget); : cast(tree, btarget);
} }

View file

@ -941,18 +941,6 @@ public class ClassReader implements Completer {
new AttributeReader(names.Code, V45_3, MEMBER_ATTRIBUTE) { new AttributeReader(names.Code, V45_3, MEMBER_ATTRIBUTE) {
protected void read(Symbol sym, int attrLen) { 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) if (readAllOfClassFile || saveParameterNames)
((MethodSymbol)sym).code = readCode(sym); ((MethodSymbol)sym).code = readCode(sym);
else else
@ -1753,6 +1741,17 @@ public class ClassReader implements Completer {
long flags = adjustMethodFlags(nextChar()); long flags = adjustMethodFlags(nextChar());
Name name = readName(nextChar()); Name name = readName(nextChar());
Type type = readType(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()) { if (name == names.init && currentOwner.hasOuterInstance()) {
// Sometimes anonymous classes don't have an outer // Sometimes anonymous classes don't have an outer
// instance, however, there is no reliable way to tell so // 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. * package. Return the object's index in the pool.
*/ */
public int put(Object value) { public int put(Object value) {
if (value instanceof MethodSymbol) value = makePoolValue(value);
value = new Method((MethodSymbol)value);
else if (value instanceof VarSymbol)
value = new Variable((VarSymbol)value);
// assert !(value instanceof Type.TypeVar); // assert !(value instanceof Type.TypeVar);
Integer index = indices.get(value); Integer index = indices.get(value);
if (index == null) { if (index == null) {
@ -115,6 +112,18 @@ public class Pool {
return index.intValue(); 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, /** Return the given object's index in the pool,
* or -1 if object is not in there. * 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 { static class Variable extends DelegatedSymbol {
VarSymbol v; VarSymbol v;
Variable(VarSymbol v) { Variable(VarSymbol v) {

View file

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

View file

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

View file

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

View file

@ -525,7 +525,8 @@ public class RichDiagnosticFormatter extends
bound = ((ErrorType)bound).getOriginalType(); bound = ((ErrorType)bound).getOriginalType();
//retrieve the bound list - if the type variable //retrieve the bound list - if the type variable
//has not been attributed the bound is not set //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) : types.getBounds(t) :
List.<Type>nil(); List.<Type>nil();

View file

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

View file

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

View file

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

View file

@ -1,7 +1,7 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @summary negative test for ambiguous defaults * @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 { class Neg01 {

View file

@ -1,7 +1,7 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @summary check that ill-formed MI hierarchies do not compile * @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 { class Neg02 {

View file

@ -1,7 +1,7 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @summary check that re-abstraction works properly * @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 { class Neg03 {

View file

@ -1,7 +1,7 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @summary check that default method must have most specific return type * @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 { class Neg04 {

View file

@ -1,7 +1,7 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @summary check that abstract methods are compatible with inherited defaults * @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 { class Neg05 {

View file

@ -1,7 +1,7 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @summary flow analysis is not run on inlined default bodies * @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 { class Neg06 {

View file

@ -1,7 +1,7 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @summary check that default overrides are properly type-checked * @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 { class Neg07 {

View file

@ -1,7 +1,7 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @summary check that default overrides are properly type-checked * @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 { class Neg08 {
interface I { interface I {

View file

@ -1,7 +1,7 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @summary check that default overrides are properly type-checked * @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; import java.util.List;

View file

@ -1,7 +1,7 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @summary check that default overrides are properly type-checked * @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 { class Neg10 {
interface I<X extends Exception> { interface I<X extends Exception> {

View file

@ -1,7 +1,7 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @summary check that default overrides are properly type-checked * @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 { class Neg11 {
interface I { interface I {

View file

@ -1,7 +1,7 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @summary check that abstract methods are discarded in overload resolution diags * @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 { 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: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) 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 3 errors

View file

@ -1,7 +1,7 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @summary check that default method overriding object members are flagged as error * @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 { interface Neg13 {
default protected Object clone() { return null; } //protected not allowed here default protected Object clone() { return null; } //protected not allowed here

View file

@ -1,7 +1,7 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @summary check that a class cannot have two sibling interfaces with a default and abstract method * @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 { class Neg14 {
interface IA { int m(); } interface IA { int m(); }

View file

@ -1,7 +1,7 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @summary check that level skipping in default super calls is correctly rejected * @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 { class Neg15 {
interface I { default void m() { } } interface I { default void m() { } }

View file

@ -1,7 +1,7 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @summary check that level skipping in default super calls is correctly rejected * @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 { class Neg16 {
interface I { default void m() { } } interface I { default void m() { } }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -54,7 +54,7 @@ public class TestDefaultMethodsSyntax {
} }
List<String> getOptions() { 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.err.prob.found.req
// key: compiler.misc.cant.access.inner.cls.constr // key: compiler.misc.cant.access.inner.cls.constr
// key: compiler.misc.invalid.mref // key: compiler.misc.invalid.mref
// options: -XDallowMethodReferences
class CantAccessInnerClsConstructor { class CantAccessInnerClsConstructor {

View file

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

View file

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

View file

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

View file

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

View file

@ -24,7 +24,6 @@
// key: compiler.misc.cant.resolve.location.args.params // key: compiler.misc.cant.resolve.location.args.params
// key: compiler.misc.location // key: compiler.misc.location
// key: compiler.err.invalid.mref // key: compiler.err.invalid.mref
// options: -XDallowMethodReferences
class CantResolveLocationArgsParamsFragment { 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.err.cant.apply.symbol
// key: compiler.misc.cyclic.inference // key: compiler.misc.cyclic.inference
// options: -XDallowLambda -XDallowPoly
class CyclicInference { class CyclicInference {
interface SAM<X> { interface SAM<X> {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -22,6 +22,7 @@
*/ */
// key: compiler.err.local.var.accessed.from.icls.needs.final // key: compiler.err.local.var.accessed.from.icls.needs.final
// options: -Xlint:-options -source 7
class LocalVarNeedsFinal { class LocalVarNeedsFinal {
Runnable m() { 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -21,7 +21,8 @@
* questions. * questions.
*/ */
// key: compiler.err.missing.ret.val // key: compiler.err.prob.found.req
// key: compiler.misc.missing.ret.val
class MissingReturnValue { class MissingReturnValue {
int m() { int m() {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -23,7 +23,6 @@
// key: compiler.err.illegal.default.super.call // key: compiler.err.illegal.default.super.call
// key: compiler.misc.overridden.default // key: compiler.misc.overridden.default
// options: -XDallowDefaultMethods
class OverriddenDefault { class OverriddenDefault {
interface I { default void m() { } } interface I { default void m() { } }
@ -33,4 +32,4 @@ class OverriddenDefault {
static class C implements J, K { static class C implements J, K {
void foo() { K.super.m(); } void foo() { K.super.m(); }
} }
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -22,7 +22,6 @@
*/ */
// key: compiler.err.unexpected.mref // key: compiler.err.unexpected.mref
// options: -XDallowMethodReferences
class UnexpectedLambda { class UnexpectedLambda {
{ (Foo::bar)++; } { (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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -21,9 +21,10 @@
* questions. * 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() { void m() {
return 3; return 3;
} }

View file

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