--- a/langtools/src/share/classes/com/sun/tools/javac/code/Type.java Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Type.java Fri Jun 08 12:45:43 2012 -0700
@@ -54,7 +54,7 @@
* package types (tag: PACKAGE, class: PackageType),
* type variables (tag: TYPEVAR, class: TypeVar),
* type arguments (tag: WILDCARD, class: WildcardType),
- * polymorphic types (tag: FORALL, class: ForAll),
+ * generic method types (tag: FORALL, class: ForAll),
* the error type (tag: ERROR, class: ErrorType).
* </pre>
*
@@ -1108,11 +1108,16 @@
public boolean isErroneous() { return qtype.isErroneous(); }
}
+ /**
+ * The type of a generic method type. It consists of a method type and
+ * a list of method type-parameters that are used within the method
+ * type.
+ */
public static class ForAll extends DelegatedType implements ExecutableType {
public List<Type> tvars;
public ForAll(List<Type> tvars, Type qtype) {
- super(FORALL, qtype);
+ super(FORALL, (MethodType)qtype);
this.tvars = tvars;
}
@@ -1131,34 +1136,6 @@
return qtype.isErroneous();
}
- /**
- * Replaces this ForAll's typevars with a set of concrete Java types
- * and returns the instantiated generic type. Subclasses should override
- * in order to check that the list of types is a valid instantiation
- * of the ForAll's typevars.
- *
- * @param actuals list of actual types
- * @param types types instance
- * @return qtype where all occurrences of tvars are replaced
- * by types in actuals
- */
- public Type inst(List<Type> actuals, Types types) {
- return types.subst(qtype, tvars, actuals);
- }
-
- /**
- * Get the type-constraints of a given kind for a given type-variable of
- * this ForAll type. Subclasses should override in order to return more
- * accurate sets of constraints.
- *
- * @param tv the type-variable for which the constraint is to be retrieved
- * @param ck the constraint kind to be retrieved
- * @return the list of types specified by the selected constraint
- */
- public List<Type> undetvars() {
- return List.nil();
- }
-
public Type map(Mapping f) {
return f.apply(qtype);
}
@@ -1168,7 +1145,7 @@
}
public MethodType asMethodType() {
- return qtype.asMethodType();
+ return (MethodType)qtype;
}
public void complete() {
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Jun 08 12:45:43 2012 -0700
@@ -702,6 +702,13 @@
return t;
}
+ Type attribIdentAsEnumType(Env<AttrContext> env, JCIdent id) {
+ Assert.check((env.enclClass.sym.flags() & ENUM) != 0);
+ id.type = env.info.scope.owner.type;
+ id.sym = env.info.scope.owner;
+ return id.type;
+ }
+
public void visitClassDef(JCClassDecl tree) {
// Local classes have not been entered yet, so we need to do it now:
if ((env.info.scope.owner.kind & (VAR | MTH)) != 0)
@@ -1529,7 +1536,7 @@
// ...and check that it is legal in the current context.
// (this will also set the tree's type)
- Type mpt = newMethTemplate(argtypes, typeargtypes);
+ Type mpt = newMethodTemplate(resultInfo.pt, argtypes, typeargtypes);
checkId(tree.meth, site, sym, localEnv, new ResultInfo(MTH, mpt),
tree.varargsElement != null);
}
@@ -1545,7 +1552,7 @@
// ... and attribute the method using as a prototype a methodtype
// whose formal argument types is exactly the list of actual
// arguments (this will also set the method symbol).
- Type mpt = newMethTemplate(argtypes, typeargtypes);
+ Type mpt = newMethodTemplate(resultInfo.pt, argtypes, typeargtypes);
localEnv.info.varArgs = false;
Type mtype = attribExpr(tree.meth, localEnv, mpt);
@@ -1608,8 +1615,8 @@
/** Obtain a method type with given argument types.
*/
- Type newMethTemplate(List<Type> argtypes, List<Type> typeargtypes) {
- MethodType mt = new MethodType(argtypes, null, null, syms.methodClass);
+ Type newMethodTemplate(Type restype, List<Type> argtypes, List<Type> typeargtypes) {
+ MethodType mt = new MethodType(argtypes, restype, null, syms.methodClass);
return (typeargtypes == null) ? mt : (Type)new ForAll(typeargtypes, mt);
}
@@ -1657,7 +1664,10 @@
// Attribute clazz expression and store
// symbol + type back into the attributed tree.
- Type clazztype = attribType(clazz, env);
+ Type clazztype = TreeInfo.isEnumInit(env.tree) ?
+ attribIdentAsEnumType(env, (JCIdent)clazz) :
+ attribType(clazz, env);
+
clazztype = chk.checkDiamond(tree, clazztype);
chk.validate(clazz, localEnv);
if (tree.encl != null) {
@@ -1883,25 +1893,23 @@
typeargtypes);
if (constructor.kind == MTH) {
- clazztype = checkMethod(site,
- constructor,
- localEnv,
- tree.args,
- argtypes,
- typeargtypes,
- localEnv.info.varArgs).getReturnType();
- } else {
- clazztype = syms.errType;
- }
-
- if (clazztype.tag == FORALL && !resultInfo.pt.isErroneous()) {
try {
- clazztype = resultInfo.checkContext.rawInstantiatePoly((ForAll)clazztype, pt(), Warner.noWarnings);
- } catch (Infer.InferenceException ex) {
+ clazztype = rawCheckMethod(site,
+ constructor,
+ resultInfo,
+ localEnv,
+ tree.args,
+ argtypes,
+ typeargtypes,
+ localEnv.info.varArgs).getReturnType();
+ } catch (Resolve.InapplicableMethodException ex) {
//an error occurred while inferring uninstantiated type-variables
resultInfo.checkContext.report(tree.clazz.pos(), clazztype, resultInfo.pt,
diags.fragment("cant.apply.diamond.1", diags.fragment("diamond", clazztype.tsym), ex.diagnostic));
+ clazztype = syms.errType;
}
+ } else {
+ clazztype = syms.errType;
}
return chk.checkClassType(tree.clazz.pos(), clazztype, true);
@@ -2255,15 +2263,6 @@
sitesym != null &&
sitesym.name == names._super;
- // If selected expression is polymorphic, strip
- // type parameters and remember in env.info.tvars, so that
- // they can be added later (in Attr.checkId and Infer.instantiateMethod).
- if (tree.selected.type.tag == FORALL) {
- ForAll pstype = (ForAll)tree.selected.type;
- env.info.tvars = pstype.tvars;
- site = tree.selected.type = pstype.qtype;
- }
-
// Determine the symbol represented by the selection.
env.info.varArgs = false;
Symbol sym = selectSym(tree, sitesym, site, env, resultInfo);
@@ -2347,7 +2346,6 @@
env.info.selectSuper = selectSuperPrev;
result = checkId(tree, site, sym, env, resultInfo, varArgs);
- env.info.tvars = List.nil();
}
//where
/** Determine symbol referenced by a Select expression,
@@ -2530,16 +2528,6 @@
? types.memberType(site, sym)
: sym.type;
- if (env.info.tvars.nonEmpty()) {
- Type owntype1 = new ForAll(env.info.tvars, owntype);
- for (List<Type> l = env.info.tvars; l.nonEmpty(); l = l.tail)
- if (!owntype.contains(l.head)) {
- log.error(tree.pos(), "undetermined.type", owntype1);
- owntype1 = types.createErrorType(owntype1);
- }
- owntype = owntype1;
- }
-
// If the variable is a constant, record constant value in
// computed type.
if (v.getConstValue() != null && isStaticReference(tree))
@@ -2551,9 +2539,10 @@
break;
case MTH: {
JCMethodInvocation app = (JCMethodInvocation)env.tree;
- owntype = checkMethod(site, sym, env, app.args,
- resultInfo.pt.getParameterTypes(), resultInfo.pt.getTypeArguments(),
- env.info.varArgs);
+ owntype = checkMethod(site, sym,
+ new ResultInfo(VAL, resultInfo.pt.getReturnType(), resultInfo.checkContext),
+ env, app.args, resultInfo.pt.getParameterTypes(),
+ resultInfo.pt.getTypeArguments(), env.info.varArgs);
break;
}
case PCK: case ERR:
@@ -2692,6 +2681,33 @@
**/
public Type checkMethod(Type site,
Symbol sym,
+ ResultInfo resultInfo,
+ Env<AttrContext> env,
+ final List<JCExpression> argtrees,
+ List<Type> argtypes,
+ List<Type> typeargtypes,
+ boolean useVarargs) {
+ try {
+ return rawCheckMethod(site, sym, resultInfo, env, argtrees, argtypes, typeargtypes, useVarargs);
+ } catch (Resolve.InapplicableMethodException ex) {
+ String key = ex.getDiagnostic() == null ?
+ "cant.apply.symbol" :
+ "cant.apply.symbol.1";
+ log.error(env.tree.pos, key,
+ Kinds.kindName(sym),
+ sym.name == names.init ? sym.owner.name : sym.name,
+ rs.methodArguments(sym.type.getParameterTypes()),
+ rs.methodArguments(argtypes),
+ Kinds.kindName(sym.owner),
+ sym.owner.type,
+ ex.getDiagnostic());
+ return types.createErrorType(site);
+ }
+ }
+
+ private Type rawCheckMethod(Type site,
+ Symbol sym,
+ ResultInfo resultInfo,
Env<AttrContext> env,
final List<JCExpression> argtrees,
List<Type> argtypes,
@@ -2717,32 +2733,19 @@
// Resolve.instantiate from the symbol's type as well as
// any type arguments and value arguments.
noteWarner.clear();
- Type owntype = rs.instantiate(env,
- site,
- sym,
- argtypes,
- typeargtypes,
- true,
- useVarargs,
- noteWarner);
+ Type owntype = rs.rawInstantiate(env,
+ site,
+ sym,
+ resultInfo,
+ argtypes,
+ typeargtypes,
+ true,
+ useVarargs,
+ noteWarner);
boolean unchecked = noteWarner.hasNonSilentLint(LintCategory.UNCHECKED);
- // If this fails, something went wrong; we should not have
- // found the identifier in the first place.
- if (owntype == null) {
- if (!pt().isErroneous())
- log.error(env.tree.pos(),
- "internal.error.cant.instantiate",
- sym, site,
- Type.toString(pt().getParameterTypes()));
- owntype = types.createErrorType(site);
- return types.createErrorType(site);
- } else if (owntype.getReturnType().tag == FORALL && !unchecked) {
- return owntype;
- } else {
- return chk.checkMethod(owntype, sym, env, argtrees, argtypes, useVarargs, unchecked);
- }
+ return chk.checkMethod(owntype, sym, env, argtrees, argtypes, useVarargs, unchecked);
}
/**
@@ -2755,7 +2758,7 @@
List<Type> argtypes,
List<Type> typeargtypes,
boolean useVarargs) {
- Type owntype = checkMethod(site, sym, env, argtrees, argtypes, typeargtypes, useVarargs);
+ Type owntype = checkMethod(site, sym, new ResultInfo(VAL, syms.voidType), env, argtrees, argtypes, typeargtypes, useVarargs);
chk.checkType(env.tree.pos(), owntype.getReturnType(), syms.voidType);
return owntype;
}
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/AttrContext.java Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/AttrContext.java Fri Jun 08 12:45:43 2012 -0700
@@ -58,10 +58,6 @@
*/
boolean varArgs = false;
- /** A list of type variables that are all-quantifed in current context.
- */
- List<Type> tvars = List.nil();
-
/** A record of the lint/SuppressWarnings currently in effect
*/
Lint lint;
@@ -80,7 +76,6 @@
info.isSelfCall = isSelfCall;
info.selectSuper = selectSuper;
info.varArgs = varArgs;
- info.tvars = tvars;
info.lint = lint;
info.enclVar = enclVar;
return info;
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Fri Jun 08 12:45:43 2012 -0700
@@ -424,10 +424,6 @@
*/
boolean compatible(Type found, Type req, Warner warn);
/**
- * Instantiate a ForAll type against a given target type 'req' in given context
- */
- Type rawInstantiatePoly(ForAll found, Type req, Warner warn);
- /**
* Report a check error
*/
void report(DiagnosticPosition pos, Type found, Type req, JCDiagnostic details);
@@ -454,10 +450,6 @@
return enclosingContext.compatible(found, req, warn);
}
- public Type rawInstantiatePoly(ForAll found, Type req, Warner warn) {
- return enclosingContext.rawInstantiatePoly(found, req, warn);
- }
-
public void report(DiagnosticPosition pos, Type found, Type req, JCDiagnostic details) {
enclosingContext.report(pos, found, req, details);
}
@@ -482,12 +474,6 @@
return types.isAssignable(found, req, warn);
}
- public Type rawInstantiatePoly(ForAll found, Type req, Warner warn) {
- if (req.tag == NONE)
- req = found.qtype.tag <= VOID ? found.qtype : syms.objectType;
- return infer.instantiateExpr(found, req, warn);
- }
-
public Warner checkWarner(DiagnosticPosition pos, Type found, Type req) {
return convertWarner(pos, found, req);
}
@@ -506,11 +492,6 @@
Type checkType(final DiagnosticPosition pos, Type found, Type req, CheckContext checkContext) {
if (req.tag == ERROR)
return req;
- if (found.tag == FORALL) {
- ForAll fa = (ForAll)found;
- Type owntype = instantiatePoly(pos, checkContext, fa, req, checkContext.checkWarner(pos, found, req));
- return checkType(pos, owntype, req, checkContext);
- }
if (req.tag == NONE)
return found;
if (checkContext.compatible(found, req, checkContext.checkWarner(pos, found, req))) {
@@ -525,32 +506,6 @@
}
}
- /** Instantiate polymorphic type to some prototype, unless
- * prototype is `anyPoly' in which case polymorphic type
- * is returned unchanged.
- */
- Type instantiatePoly(DiagnosticPosition pos, CheckContext checkContext, ForAll t, Type pt, Warner warn) throws Infer.NoInstanceException {
- try {
- return checkContext.rawInstantiatePoly(t, pt, warn);
- } catch (final Infer.NoInstanceException ex) {
- JCDiagnostic d = ex.getDiagnostic();
- if (d != null) {
- if (ex.isAmbiguous) {
- d = diags.fragment("undetermined.type", t, d);
- }
- }
- checkContext.report(pos, t, pt, d);
- return types.createErrorType(pt);
- } catch (Infer.InvalidInstanceException ex) {
- JCDiagnostic d = ex.getDiagnostic();
- if (d != null) {
- d = diags.fragment("invalid.inferred.types", t.tvars, d);
- }
- checkContext.report(pos, t, pt, d);
- return types.createErrorType(pt);
- }
- }
-
/** Check that a given type can be cast to a given target type.
* Return the result of the cast.
* @param pos Position to be used for error reporting.
@@ -561,10 +516,7 @@
return checkCastable(pos, found, req, basicHandler);
}
Type checkCastable(DiagnosticPosition pos, Type found, Type req, CheckContext checkContext) {
- if (found.tag == FORALL) {
- instantiatePoly(pos, basicHandler, (ForAll) found, req, castWarner(pos, found, req));
- return req;
- } else if (types.isCastable(found, req, castWarner(pos, found, req))) {
+ if (types.isCastable(found, req, castWarner(pos, found, req))) {
return req;
} else {
checkContext.report(pos, found, req, diags.fragment("inconvertible.types", found, req));
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java Fri Jun 08 12:45:43 2012 -0700
@@ -214,16 +214,23 @@
* If no instantiation exists, or if several incomparable
* best instantiations exist throw a NoInstanceException.
*/
- public Type instantiateExpr(ForAll that,
- Type to,
+ public List<Type> instantiateUninferred(DiagnosticPosition pos,
+ List<Type> undetvars,
+ List<Type> tvars,
+ MethodType mtype,
+ Attr.ResultInfo resultInfo,
Warner warn) throws InferenceException {
- List<Type> undetvars = that.undetvars();
- Type qtype1 = types.subst(that.qtype, that.tvars, undetvars);
+ Type to = resultInfo.pt;
+ if (to.tag == NONE) {
+ to = mtype.getReturnType().tag <= VOID ?
+ mtype.getReturnType() : syms.objectType;
+ }
+ Type qtype1 = types.subst(mtype.getReturnType(), tvars, undetvars);
if (!types.isSubtype(qtype1,
qtype1.tag == UNDETVAR ? types.boxedTypeOrType(to) : to)) {
throw unambiguousNoInstanceException
.setMessage("infer.no.conforming.instance.exists",
- that.tvars, that.qtype, to);
+ tvars, mtype.getReturnType(), to);
}
List<Type> insttypes;
@@ -232,32 +239,32 @@
insttypes = List.nil();
for (Type t : undetvars) {
UndetVar uv = (UndetVar)t;
- if (uv.inst == null && (uv.eq.nonEmpty() || !Type.containsAny(uv.hibounds, that.tvars))) {
+ if (uv.inst == null && (uv.eq.nonEmpty() || !Type.containsAny(uv.hibounds, tvars))) {
maximizeInst((UndetVar)t, warn);
stuck = false;
}
insttypes = insttypes.append(uv.inst == null ? uv.qtype : uv.inst);
}
- if (!Type.containsAny(insttypes, that.tvars)) {
+ if (!Type.containsAny(insttypes, tvars)) {
//all variables have been instantiated - exit
break;
} else if (stuck) {
//some variables could not be instantiated because of cycles in
//upper bounds - provide a (possibly recursive) default instantiation
insttypes = types.subst(insttypes,
- that.tvars,
- instantiateAsUninferredVars(undetvars, that.tvars));
+ tvars,
+ instantiateAsUninferredVars(undetvars, tvars));
break;
} else {
//some variables have been instantiated - replace newly instantiated
//variables in remaining upper bounds and continue
for (Type t : undetvars) {
UndetVar uv = (UndetVar)t;
- uv.hibounds = types.subst(uv.hibounds, that.tvars, insttypes);
+ uv.hibounds = types.subst(uv.hibounds, tvars, insttypes);
}
}
}
- return that.inst(insttypes, types);
+ return insttypes;
}
/**
@@ -296,18 +303,19 @@
/** Instantiate method type `mt' by finding instantiations of
* `tvars' so that method can be applied to `argtypes'.
*/
- public Type instantiateMethod(final Env<AttrContext> env,
+ public Type instantiateMethod(Env<AttrContext> env,
List<Type> tvars,
MethodType mt,
- final Symbol msym,
- final List<Type> argtypes,
- final boolean allowBoxing,
- final boolean useVarargs,
- final Warner warn) throws InferenceException {
+ Attr.ResultInfo resultInfo,
+ Symbol msym,
+ List<Type> argtypes,
+ boolean allowBoxing,
+ boolean useVarargs,
+ Warner warn) throws InferenceException {
//-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG
- final List<Type> undetvars = makeUndetvars(tvars);
+ List<Type> undetvars = makeUndetvars(tvars);
- final List<Type> capturedArgs =
+ List<Type> capturedArgs =
rs.checkRawArgumentsAcceptable(env, undetvars, argtypes, mt.getParameterTypes(),
allowBoxing, useVarargs, warn, new InferenceCheckHandler(undetvars));
@@ -344,38 +352,23 @@
mt = (MethodType)types.subst(mt, tvars, insttypes.toList());
- if (!restvars.isEmpty()) {
- // if there are uninstantiated variables,
- // quantify result type with them
- final List<Type> inferredTypes = insttypes.toList();
- final List<Type> all_tvars = tvars; //this is the wrong tvars
- return new UninferredMethodType(env.tree.pos(), msym, mt, restvars.toList()) {
- @Override
- List<Type> undetvars() {
- return restundet.toList();
- }
- @Override
- void instantiateReturnType(Type restype, List<Type> inferred, Types types) throws NoInstanceException {
- Type owntype = new MethodType(types.subst(getParameterTypes(), tvars, inferred),
- restype,
- types.subst(getThrownTypes(), tvars, inferred),
- qtype.tsym);
- // check that actuals conform to inferred formals
- warn.clear();
- checkArgumentsAcceptable(env, capturedArgs, owntype.getParameterTypes(), allowBoxing, useVarargs, warn);
- // check that inferred bounds conform to their bounds
- checkWithinBounds(all_tvars, undetvars,
- types.subst(inferredTypes, tvars, inferred), warn);
- qtype = chk.checkMethod(owntype, msym, env, TreeInfo.args(env.tree), capturedArgs, useVarargs, warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED));
- }
- };
+ if (!restvars.isEmpty() && resultInfo != null) {
+ List<Type> restInferred =
+ instantiateUninferred(env.tree.pos(), restundet.toList(), restvars.toList(), mt, resultInfo, warn);
+ checkWithinBounds(tvars, undetvars,
+ types.subst(insttypes.toList(), restvars.toList(), restInferred), warn);
+ mt = (MethodType)types.subst(mt, restvars.toList(), restInferred);
+ if (rs.verboseResolutionMode.contains(VerboseResolutionMode.DEFERRED_INST)) {
+ log.note(env.tree.pos, "deferred.method.inst", msym, mt, resultInfo.pt);
+ }
}
- else {
+
+ if (restvars.isEmpty() || resultInfo != null) {
// check that actuals conform to inferred formals
checkArgumentsAcceptable(env, capturedArgs, mt.getParameterTypes(), allowBoxing, useVarargs, warn);
- // return instantiated version of method type
- return mt;
}
+ // return instantiated version of method type
+ return mt;
}
//where
@@ -404,60 +397,6 @@
}
}
- /**
- * A delegated type representing a partially uninferred method type.
- * The return type of a partially uninferred method type is a ForAll
- * type - when the return type is instantiated (see Infer.instantiateExpr)
- * the underlying method type is also updated.
- */
- abstract class UninferredMethodType extends DelegatedType {
-
- final List<Type> tvars;
- final Symbol msym;
- final DiagnosticPosition pos;
-
- public UninferredMethodType(DiagnosticPosition pos, Symbol msym, MethodType mtype, List<Type> tvars) {
- super(METHOD, new MethodType(mtype.argtypes, null, mtype.thrown, mtype.tsym));
- this.tvars = tvars;
- this.msym = msym;
- this.pos = pos;
- asMethodType().restype = new UninferredReturnType(tvars, mtype.restype);
- }
-
- @Override
- public MethodType asMethodType() {
- return qtype.asMethodType();
- }
-
- @Override
- public Type map(Mapping f) {
- return qtype.map(f);
- }
-
- abstract void instantiateReturnType(Type restype, List<Type> inferred, Types types);
-
- abstract List<Type> undetvars();
-
- class UninferredReturnType extends ForAll {
- public UninferredReturnType(List<Type> tvars, Type restype) {
- super(tvars, restype);
- }
- @Override
- public Type inst(List<Type> actuals, Types types) {
- Type newRestype = super.inst(actuals, types);
- instantiateReturnType(newRestype, actuals, types);
- if (rs.verboseResolutionMode.contains(VerboseResolutionMode.DEFERRED_INST)) {
- log.note(pos, "deferred.method.inst", msym, UninferredMethodType.this.qtype, newRestype);
- }
- return UninferredMethodType.this.qtype.getReturnType();
- }
- @Override
- public List<Type> undetvars() {
- return UninferredMethodType.this.undetvars();
- }
- }
- }
-
private void checkArgumentsAcceptable(Env<AttrContext> env, List<Type> actuals, List<Type> formals,
boolean allowBoxing, boolean useVarargs, Warner warn) {
try {
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Fri Jun 08 12:45:43 2012 -0700
@@ -248,7 +248,7 @@
final Name name,
final Env<AttrContext> env) {
if (tsym.kind != TYP) {
- log.error(pos, "static.imp.only.classes.and.interfaces");
+ log.error(DiagnosticFlag.RECOVERABLE, pos, "static.imp.only.classes.and.interfaces");
return;
}
@@ -620,7 +620,11 @@
DeferredLintHandler prevLintHandler =
chk.setDeferredLintHandler(deferredLintHandler.setPos(tree.pos()));
try {
- attr.attribType(tree.vartype, localEnv);
+ if (TreeInfo.isEnumInit(tree)) {
+ attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype);
+ } else {
+ attr.attribType(tree.vartype, localEnv);
+ }
} finally {
chk.setDeferredLintHandler(prevLintHandler);
}
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Fri Jun 08 12:45:43 2012 -0700
@@ -224,12 +224,8 @@
JCDiagnostic getVerboseApplicableCandidateDiag(int pos, Symbol sym, Type inst) {
JCDiagnostic subDiag = null;
- if (inst.getReturnType().tag == FORALL) {
- Type diagType = types.createMethodTypeWithReturn(inst.asMethodType(),
- ((ForAll)inst.getReturnType()).qtype);
- subDiag = diags.fragment("partial.inst.sig", diagType);
- } else if (sym.type.tag == FORALL) {
- subDiag = diags.fragment("full.inst.sig", inst.asMethodType());
+ if (sym.type.tag == FORALL) {
+ subDiag = diags.fragment("partial.inst.sig", inst);
}
String key = subDiag == null ?
@@ -442,6 +438,7 @@
Type rawInstantiate(Env<AttrContext> env,
Type site,
Symbol m,
+ ResultInfo resultInfo,
List<Type> argtypes,
List<Type> typeargtypes,
boolean allowBoxing,
@@ -454,11 +451,7 @@
// tvars is the list of formal type variables for which type arguments
// need to inferred.
- List<Type> tvars = null;
- if (env.info.tvars != null) {
- tvars = types.newInstances(env.info.tvars);
- mt = types.subst(mt, env.info.tvars, tvars);
- }
+ List<Type> tvars = List.nil();
if (typeargtypes == null) typeargtypes = List.nil();
if (mt.tag != FORALL && typeargtypes.nonEmpty()) {
// This is not a polymorphic method, but typeargs are supplied
@@ -499,6 +492,7 @@
return infer.instantiateMethod(env,
tvars,
(MethodType)mt,
+ resultInfo,
m,
argtypes,
allowBoxing,
@@ -515,13 +509,14 @@
Type instantiate(Env<AttrContext> env,
Type site,
Symbol m,
+ ResultInfo resultInfo,
List<Type> argtypes,
List<Type> typeargtypes,
boolean allowBoxing,
boolean useVarargs,
Warner warn) {
try {
- return rawInstantiate(env, site, m, argtypes, typeargtypes,
+ return rawInstantiate(env, site, m, resultInfo, argtypes, typeargtypes,
allowBoxing, useVarargs, warn);
} catch (InapplicableMethodException ex) {
return null;
@@ -937,7 +932,7 @@
if (!sym.isInheritedIn(site.tsym, types)) return bestSoFar;
Assert.check(sym.kind < AMBIGUOUS);
try {
- Type mt = rawInstantiate(env, site, sym, argtypes, typeargtypes,
+ Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes,
allowBoxing, useVarargs, Warner.noWarnings);
if (!operator)
currentResolutionContext.addApplicableCandidate(sym, mt);
@@ -1071,7 +1066,7 @@
private boolean signatureMoreSpecific(Env<AttrContext> env, Type site, Symbol m1, Symbol m2, boolean allowBoxing, boolean useVarargs) {
noteWarner.clear();
Type mtype1 = types.memberType(site, adjustVarargs(m1, m2, useVarargs));
- Type mtype2 = instantiate(env, site, adjustVarargs(m2, m1, useVarargs),
+ Type mtype2 = instantiate(env, site, adjustVarargs(m2, m1, useVarargs), null,
types.lowerBoundArgtypes(mtype1), null,
allowBoxing, false, noteWarner);
return mtype2 != null &&
--- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Fri Jun 08 12:45:43 2012 -0700
@@ -419,9 +419,6 @@
compiler.err.int.number.too.large=\
integer number too large: {0}
-compiler.err.internal.error.cant.instantiate=\
- internal error; cannot instantiate {0} at {1} to ({2})
-
compiler.err.intf.annotation.members.cant.have.params=\
@interface members may not have parameters
@@ -783,11 +780,6 @@
compiler.err.undef.label=\
undefined label: {0}
-# 0: list of type, 1: message segment
-compiler.misc.invalid.inferred.types=\
- invalid inferred types for {0}\n\
- reason: {1}
-
# 0: message segment, 1: unused
compiler.err.cant.apply.diamond=\
cannot infer type arguments for {0}
@@ -1582,11 +1574,6 @@
## The following are all possible strings for the last argument of all those
## diagnostics whose key ends in ".1"
-# 0: type, 1: message segment
-compiler.misc.undetermined.type=\
- cannot infer type arguments for {0}\n\
- reason: {1}
-
# 0: type, 1: list of type
compiler.misc.no.unique.maximal.instance.exists=\
no unique maximal instance exists for type variable {0} with upper bounds {1}
@@ -1983,10 +1970,6 @@
({2})
# 0: type
-compiler.misc.full.inst.sig=\
- fully instantiated to: {0}
-
-# 0: type
compiler.misc.partial.inst.sig=\
partially instantiated to: {0}
--- a/langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Fri Jun 08 12:45:43 2012 -0700
@@ -237,6 +237,15 @@
}
}
+ public static boolean isEnumInit(JCTree tree) {
+ switch (tree.getTag()) {
+ case VARDEF:
+ return (((JCVariableDecl)tree).mods.flags & ENUM) != 0;
+ default:
+ return false;
+ }
+ }
+
/**
* Return true if the AST corresponds to a static select of the kind A.B
*/
--- a/langtools/test/tools/javac/6758789/T6758789b.out Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/test/tools/javac/6758789/T6758789b.out Fri Jun 08 12:45:43 2012 -0700
@@ -1,4 +1,4 @@
-T6758789b.java:16:11: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), T6758789a.Foo, T6758789a.Foo<X>
+T6758789b.java:16:11: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), T6758789a.Foo, T6758789a.Foo<java.lang.Object>
T6758789b.java:16:10: compiler.warn.unchecked.meth.invocation.applied: kindname.method, m, T6758789a.Foo<X>, T6758789a.Foo, kindname.class, T6758789a
- compiler.err.warnings.and.werror
1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T7159016.java Fri Jun 08 12:45:43 2012 -0700
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2010, 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.
+ */
+
+/*
+ * @test
+ * @bug 7159016
+ * @summary Static import of member in processor-generated class fails in JDK 7
+ * @library lib
+ * @build JavacTestingAbstractProcessor
+ * @run main T7159016
+ * @author Jessie Glick
+ */
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Collections;
+import java.util.Set;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.TypeElement;
+import javax.tools.Diagnostic;
+import javax.tools.JavaCompiler;
+import javax.tools.ToolProvider;
+
+public class T7159016 {
+ public static void main(String[] args) throws Exception {
+ File src = new File("C.java");
+ Writer w = new FileWriter(src);
+ try {
+ w.write("import static p.Generated.m;\nclass C { {m(); } }\n");
+ w.flush();
+ } finally {
+ w.close();
+ }
+ JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
+ JavaCompiler.CompilationTask task = jc.getTask(null, null, null, null, null,
+ jc.getStandardFileManager(null, null, null).getJavaFileObjects(src));
+ task.setProcessors(Collections.singleton(new Proc()));
+ if (!task.call()) {
+ throw new Error("Test failed");
+ }
+ }
+
+ private static class Proc extends JavacTestingAbstractProcessor {
+ int written;
+ @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ if (roundEnv.processingOver() || written++ > 0) {
+ return false;
+ }
+ messager.printMessage(Diagnostic.Kind.NOTE, "writing Generated.java");
+ try {
+ Writer w = processingEnv.getFiler().createSourceFile("p.Generated").openWriter();
+ try {
+ w.write("package p; public class Generated { public static void m() { } }");
+ } finally {
+ w.close();
+ }
+ } catch (IOException x) {
+ messager.printMessage(Diagnostic.Kind.ERROR, x.toString());
+ }
+ return true;
+ }
+ }
+}
--- a/langtools/test/tools/javac/diags/examples.not-yet.txt Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/test/tools/javac/diags/examples.not-yet.txt Fri Jun 08 12:45:43 2012 -0700
@@ -5,7 +5,6 @@
compiler.err.cant.read.file # (apt.JavaCompiler?)
compiler.err.cant.select.static.class.from.param.type
compiler.err.illegal.char.for.encoding
-compiler.err.internal.error.cant.instantiate # Attr: should not happen
compiler.err.io.exception # (javah.JavahTask?)
compiler.err.limit.code # Code
compiler.err.limit.code.too.large.for.try.stmt # Gen
--- a/langtools/test/tools/javac/diags/examples/ApplicableMethodFound1.java Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/test/tools/javac/diags/examples/ApplicableMethodFound1.java Fri Jun 08 12:45:43 2012 -0700
@@ -23,7 +23,7 @@
// key: compiler.misc.applicable.method.found.1
// key: compiler.note.verbose.resolve.multi
-// key: compiler.misc.full.inst.sig
+// key: compiler.misc.partial.inst.sig
// options: -XDverboseResolution=applicable,success
class ApplicableMethodFound1 {
--- a/langtools/test/tools/javac/diags/examples/CantApplyDiamond1.java Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/test/tools/javac/diags/examples/CantApplyDiamond1.java Fri Jun 08 12:45:43 2012 -0700
@@ -23,7 +23,7 @@
// key: compiler.err.prob.found.req.1
// key: compiler.misc.cant.apply.diamond.1
-// key: compiler.misc.no.conforming.assignment.exists
+// key: compiler.misc.inferred.do.not.conform.to.upper.bounds
// key: compiler.misc.diamond
class CantApplyDiamond1<X> {
--- a/langtools/test/tools/javac/diags/examples/FullInstSig.java Thu Jun 07 12:10:41 2012 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2011, 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.misc.applicable.method.found.1
-// key: compiler.note.verbose.resolve.multi
-// key: compiler.misc.full.inst.sig
-// options: -XDverboseResolution=applicable,success
-
-class FullInstSig {
-
- <X> void m(X x) {}
-
- { m(1); }
-}
--- a/langtools/test/tools/javac/diags/examples/IncompatibleTypes1.java Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/test/tools/javac/diags/examples/IncompatibleTypes1.java Fri Jun 08 12:45:43 2012 -0700
@@ -22,7 +22,7 @@
*/
// key: compiler.misc.infer.no.conforming.instance.exists
-// key: compiler.err.prob.found.req.1
+// key: compiler.err.cant.apply.symbol.1
class IncompatibleTypes1<V> {
<T> IncompatibleTypes1<Integer> m() {
--- a/langtools/test/tools/javac/diags/examples/InferredDoNotConformToLower.java Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/test/tools/javac/diags/examples/InferredDoNotConformToLower.java Fri Jun 08 12:45:43 2012 -0700
@@ -21,8 +21,7 @@
* questions.
*/
-// key: compiler.misc.invalid.inferred.types
-// key: compiler.err.prob.found.req.1
+// key: compiler.err.cant.apply.symbol.1
// key: compiler.misc.inferred.do.not.conform.to.lower.bounds
import java.util.*;
--- a/langtools/test/tools/javac/diags/examples/InvalidInferredTypes.java Thu Jun 07 12:10:41 2012 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2010, 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.1
-// key: compiler.misc.invalid.inferred.types
-// key: compiler.misc.inferred.do.not.conform.to.upper.bounds
-
-import java.util.*;
-
-class InvalidInferredTypes {
-
- <S extends String> List<S> m() { return null; }
-
- void test() {
- List<Integer> li = m();
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/diags/examples/NoUniqueMaximalInstance.java Fri Jun 08 12:45:43 2012 -0700
@@ -0,0 +1,31 @@
+/*
+ * 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.cant.apply.symbol.1
+// key: compiler.misc.no.unique.maximal.instance.exists
+
+class NoUniqueMaximalInstance {
+ <Z extends Integer> Z m() { return null; }
+
+ { String s = m(); }
+}
--- a/langtools/test/tools/javac/diags/examples/UndeterminedType1.java Thu Jun 07 12:10:41 2012 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2010, 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.1
-// key: compiler.misc.undetermined.type
-// key: compiler.misc.no.unique.maximal.instance.exists
-
-class UndeterminedType1<V> {
- <T extends Integer & Runnable> UndeterminedType1<T> m() {
- return null;
- }
-
-
- UndeterminedType1<? extends String> c2 = m();
-}
--- a/langtools/test/tools/javac/diags/examples/WhereFreshTvar.java Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/test/tools/javac/diags/examples/WhereFreshTvar.java Fri Jun 08 12:45:43 2012 -0700
@@ -22,10 +22,9 @@
*/
// key: compiler.misc.where.fresh.typevar
-// key: compiler.misc.where.description.typevar.1
-// key: compiler.misc.where.typevar
-// key: compiler.misc.invalid.inferred.types
-// key: compiler.err.prob.found.req.1
+// key: compiler.misc.where.description.typevar
+// key: compiler.err.cant.apply.symbol.1
+// key: compiler.misc.no.args
// key: compiler.misc.inferred.do.not.conform.to.upper.bounds
// options: -XDdiags=where,simpleNames
// run: simple
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/enum/7160084/T7160084a.java Fri Jun 08 12:45:43 2012 -0700
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+/*
+ * @test
+ * @bug 7160084
+ * @summary javac fails to compile an apparently valid class/interface combination
+ */
+public class T7160084a {
+
+ static int assertionCount = 0;
+
+ static void assertTrue(boolean cond) {
+ assertionCount++;
+ if (!cond) {
+ throw new AssertionError();
+ }
+ }
+
+ interface Intf {
+ enum MyEnumA {
+ AA(""),
+ UNUSED("");
+
+ private MyEnumA(String s) { }
+ }
+ }
+
+ enum MyEnumA implements Intf {
+ AA("");
+
+ private MyEnumA(String s) { }
+ }
+
+ public static void main(String... args) {
+ assertTrue(MyEnumA.values().length == 1);
+ assertTrue(Intf.MyEnumA.values().length == 2);
+ assertTrue(assertionCount == 2);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/enum/7160084/T7160084b.java Fri Jun 08 12:45:43 2012 -0700
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+/*
+ * @test
+ * @bug 7160084
+ * @summary javac fails to compile an apparently valid class/interface combination
+ */
+public class T7160084b {
+
+ static int assertionCount = 0;
+
+ static void assertTrue(boolean cond) {
+ assertionCount++;
+ if (!cond) {
+ throw new AssertionError();
+ }
+ }
+
+ interface Extras {
+ static class Enums {
+ static class Component {
+ Component() { throw new RuntimeException("oops!"); }
+ }
+ }
+ }
+
+ interface Test {
+ public class Enums {
+ interface Widget {
+ enum Component { X, Y };
+ }
+
+ enum Component implements Widget, Extras {
+ Z;
+ };
+
+ public static void test() {
+ assertTrue(Component.values().length == 1);
+ }
+ }
+ }
+
+ public static void main(String[] args) {
+ Test.Enums.test();
+ assertTrue(assertionCount == 1);
+ }
+}
--- a/langtools/test/tools/javac/generics/7015430/T7015430.out Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/test/tools/javac/generics/7015430/T7015430.out Fri Jun 08 12:45:43 2012 -0700
@@ -1,14 +1,14 @@
-T7015430.java:41:15: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<E>
+T7015430.java:41:15: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.Exception>
T7015430.java:41:14: compiler.warn.unchecked.meth.invocation.applied: kindname.method, empty, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
T7015430.java:50:42: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
T7015430.java:50:41: compiler.warn.unchecked.meth.invocation.applied: kindname.method, empty, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
-T7015430.java:68:22: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<E>
+T7015430.java:68:22: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.Exception>
T7015430.java:68:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
T7015430.java:77:40: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
T7015430.java:77:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
T7015430.java:104:41: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
T7015430.java:104:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
-T7015430.java:113:22: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<E>
+T7015430.java:113:22: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.Exception>
T7015430.java:113:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
T7015430.java:41:14: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
T7015430.java:68:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
--- a/langtools/test/tools/javac/generics/7151802/T7151802.out Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/test/tools/javac/generics/7151802/T7151802.out Fri Jun 08 12:45:43 2012 -0700
@@ -1,5 +1,5 @@
T7151802.java:14:31: compiler.warn.unchecked.meth.invocation.applied: kindname.method, get1, Z, T7151802.Foo, kindname.class, T7151802
-T7151802.java:22:31: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), T7151802.Foo, T7151802.Foo<Z>
+T7151802.java:22:31: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), T7151802.Foo, T7151802.Foo<java.lang.Object>
T7151802.java:22:30: compiler.warn.unchecked.meth.invocation.applied: kindname.method, get3, T7151802.Foo<Z>, T7151802.Foo, kindname.class, T7151802
T7151802.java:30:36: compiler.warn.unchecked.meth.invocation.applied: kindname.method, get5, compiler.misc.no.args, compiler.misc.no.args, kindname.class, T7151802
T7151802.java:38:32: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), T7151802.Foo, T7151802.Foo<java.lang.String>
--- a/langtools/test/tools/javac/generics/inference/6315770/T6315770.out Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/test/tools/javac/generics/inference/6315770/T6315770.out Fri Jun 08 12:45:43 2012 -0700
@@ -1,3 +1,3 @@
-T6315770.java:16:42: compiler.err.prob.found.req.1: (compiler.misc.undetermined.type: <T>T6315770<T>, (compiler.misc.no.unique.maximal.instance.exists: T, java.lang.String,java.lang.Integer,java.lang.Runnable))
-T6315770.java:17:40: compiler.err.prob.found.req.1: (compiler.misc.invalid.inferred.types: T, (compiler.misc.inferred.do.not.conform.to.lower.bounds: java.lang.Integer&java.lang.Runnable, java.lang.String))
+T6315770.java:16:42: compiler.err.cant.apply.symbol.1: kindname.method, m, compiler.misc.no.args, compiler.misc.no.args, kindname.class, T6315770<V>, (compiler.misc.no.unique.maximal.instance.exists: T, java.lang.String,java.lang.Integer,java.lang.Runnable)
+T6315770.java:17:40: compiler.err.cant.apply.symbol.1: kindname.method, m, compiler.misc.no.args, compiler.misc.no.args, kindname.class, T6315770<V>, (compiler.misc.inferred.do.not.conform.to.lower.bounds: java.lang.Integer&java.lang.Runnable, java.lang.String)
2 errors
--- a/langtools/test/tools/javac/generics/inference/6638712/T6638712b.out Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/test/tools/javac/generics/inference/6638712/T6638712b.out Fri Jun 08 12:45:43 2012 -0700
@@ -1,2 +1,2 @@
-T6638712b.java:14:21: compiler.err.prob.found.req.1: (compiler.misc.invalid.inferred.types: T, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, java.lang.String,java.lang.Object))
+T6638712b.java:14:21: compiler.err.cant.apply.symbol.1: kindname.method, m, I, T6638712b<java.lang.Integer>, kindname.class, T6638712b<X>, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, java.lang.String,java.lang.Object)
1 error
--- a/langtools/test/tools/javac/generics/inference/6638712/T6638712e.out Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/test/tools/javac/generics/inference/6638712/T6638712e.out Fri Jun 08 12:45:43 2012 -0700
@@ -1,2 +1,2 @@
-T6638712e.java:17:27: compiler.err.prob.found.req.1: (compiler.misc.invalid.inferred.types: X, (compiler.misc.no.conforming.assignment.exists: T6638712e.Foo<java.lang.Boolean,java.lang.Boolean>, T6638712e.Foo<? super java.lang.Object,? extends java.lang.Boolean>))
+T6638712e.java:17:27: compiler.err.cant.apply.symbol.1: kindname.method, m, T6638712e.Foo<? super X,? extends A>, T6638712e.Foo<java.lang.Boolean,java.lang.Boolean>, kindname.class, T6638712e.Foo<A,B>, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Object, java.lang.Boolean,java.lang.Object)
1 error
--- a/langtools/test/tools/javac/generics/inference/6650759/T6650759m.out Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/test/tools/javac/generics/inference/6650759/T6650759m.out Fri Jun 08 12:45:43 2012 -0700
@@ -1,2 +1,2 @@
-T6650759m.java:43:36: compiler.err.prob.found.req.1: (compiler.misc.invalid.inferred.types: Z, (compiler.misc.inferred.do.not.conform.to.lower.bounds: java.lang.Integer, java.lang.String))
+T6650759m.java:43:36: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List<? extends java.util.List<? super Z>>, java.util.ArrayList<java.util.ArrayList<java.lang.Integer>>, kindname.class, T6650759m, (compiler.misc.inferred.do.not.conform.to.lower.bounds: java.lang.Integer, java.lang.String)
1 error
--- a/langtools/test/tools/javac/generics/inference/7154127/T7154127.out Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/test/tools/javac/generics/inference/7154127/T7154127.out Fri Jun 08 12:45:43 2012 -0700
@@ -1,2 +1,2 @@
-T7154127.java:19:49: compiler.err.prob.found.req.1: (compiler.misc.invalid.inferred.types: T,Y,U, (compiler.misc.inferred.do.not.conform.to.upper.bounds: Y, T7154127.D,T7154127.B<U>))
+T7154127.java:19:49: compiler.err.cant.apply.symbol.1: kindname.method, m, compiler.misc.no.args, compiler.misc.no.args, kindname.class, T7154127, (compiler.misc.inferred.do.not.conform.to.upper.bounds: Y, T7154127.D,T7154127.B<U>)
1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/rawOverride/7157798/Test1.java Fri Jun 08 12:45:43 2012 -0700
@@ -0,0 +1,116 @@
+/*
+ * 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.
+ */
+
+/**
+ * @test
+ * @bug 7062745 7157798
+ * @summary Test inheritance of same-name methods from mulitple interfaces
+ when the methods have compatible return types
+ * @compile Test1.java
+ */
+
+import java.util.*;
+
+interface A { List<Number> getList(); }
+interface B { List getList(); }
+
+interface AB extends A, B {} //return type: List<Number>
+
+interface C<T> { List<T> getList(); }
+
+interface BC<T> extends B, C<T> {} //return type: List<T>
+
+interface D { Number m(); }
+interface E { Double m(); }
+
+interface DE extends D, E {} //return type: Double
+
+interface F { ArrayList getList(); }
+interface G { Collection getList(); }
+
+interface AG extends A, G{}; //return type: List<Number>
+
+interface CF<T> extends C<T>, F {} //return type: ArrayList
+
+interface CG<T> extends C<T>, G {} //return type: List<T>
+
+interface H<T> { Iterable<T> getList(); }
+
+interface CH<T> extends C<T>, H<T> {} //return type: List<T>
+
+interface CFGH<T> extends C<T>, F, G, H<T> {} //return type: ArrayList
+
+
+class Test1 {
+
+ //raw and typed return types:
+ void test(AB ab) {
+ Number n = ab.getList().get(1);
+ }
+
+ void test(BC<String> bc) {
+ String s = bc.getList().get(1);
+ }
+
+ void testRaw(BC bc) {
+ List list = bc.getList();
+ }
+
+ void testWildCard(BC<?> bc) {
+ List<?> list = bc.getList();
+ }
+
+ <T> void testGeneric(BC<T> bc) {
+ T t = bc.getList().get(1);
+ }
+
+ //covariant return:
+ void test(DE de) {
+ Double d = de.m();
+ }
+
+ //mixed:
+ void test(AG ag) {
+ Number n = ag.getList().get(0);
+ }
+
+ void test(CF<Integer> cf) {
+ ArrayList list = cf.getList();
+ }
+
+ void test(CG<String> cg) {
+ String s = cg.getList().get(0);
+ }
+
+ void test(CH<String> ch) {
+ String s = ch.getList().get(0);
+ }
+
+ void test(CFGH<Double> cfgh) {
+ ArrayList list = cfgh.getList();
+ }
+
+ void testWildCard(CFGH<?> cfgh) {
+ ArrayList list = cfgh.getList();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/rawOverride/7157798/Test2.java Fri Jun 08 12:45:43 2012 -0700
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+/**
+ * @test
+ * @bug 7062745 7157798
+ * @summary Test inheritance of same-name methods from multiple interfaces
+ when the methods have compatible parameter types and return types
+ * @compile Test2.java
+ */
+
+import java.util.*;
+
+interface A { void m(Map map); }
+interface B { void m(Map<Number, String> map); }
+
+interface AB extends A, B {} //paramter type: Map<Number, String>
+
+interface C<K, V> { List<V> getList(Map<K, V> map); }
+interface D { ArrayList getList(Map map); }
+
+interface CD<K, V> extends C<K, V>, D {} //paramter type: Map<K, V>
+
+interface E<T> { T get(List<?> list); }
+interface F<T> { T get(List list); }
+
+interface EF<T1, T2 extends T1> extends E<T1>, F<T2> {} //parameter type: List<?>
+
+class Test2 {
+
+ //compatible parameter types:
+ void test(AB ab) {
+ ab.m(new HashMap<Number, String>());
+ }
+
+ //compatible parameter types and return types:
+ void testRaw(CD cd) { //return type: ArrayList
+ ArrayList al = cd.getList(new HashMap());
+ }
+
+ <K, V> void testGeneric(CD<K, V> cd) { //return type: List<V>
+ V v = cd.getList(new HashMap<K, V>()).get(0);
+ }
+
+ void test(CD<Number, String> cd) { //return type: List<String>
+ String s = cd.getList(new HashMap<Number, String>()).get(0);
+ }
+
+ void test(EF<Number, Integer> ef) { //return type: Number
+ Number n = ef.get(new ArrayList<Integer>());
+ }
+
+ <T, U extends T> void testGeneric(EF<T, U> ef) { //return type: T
+ T t = ef.get(new ArrayList<U>());
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/rawOverride/7157798/Test3.java Fri Jun 08 12:45:43 2012 -0700
@@ -0,0 +1,37 @@
+/**
+ * @test /nodynamiccopyright/
+ * @bug 7062745 7157798
+ * @summary Negative test of conflicting same-name methods inherited from multiple interfaces when return type not compatible
+ * @compile/fail/ref=Test3.out -Werror -Xlint:unchecked -XDrawDiagnostics Test3.java
+ */
+
+import java.util.List;
+import java.io.Serializable;
+
+interface A { int m(); }
+interface B { Integer m(); }
+
+interface AB extends A, B {} //error
+
+interface C { List<Integer> m(); }
+interface D { List<Number> m(); }
+
+interface CD extends C, D {} //error
+
+interface E<T> { T m(); }
+interface F<T> { T m(); }
+interface G { Serializable m(); }
+
+interface BE extends B, E<Number> {} //ok, covariant return
+
+interface BE2<T> extends B, E<T> {} //error
+
+interface EF<T> extends E<T>, F<T> {} //ok
+
+interface EF2<U, V extends U> extends E<U>, F<V> {} //ok, covariant return
+
+interface EF3<U, V> extends E<U>, F<V> {} //error
+
+interface EG<T extends Number> extends E<T>, G {} //ok
+
+interface EFG<U extends Serializable, V extends Serializable> extends E<U>, F<V>, G {} //error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/rawOverride/7157798/Test3.out Fri Jun 08 12:45:43 2012 -0700
@@ -0,0 +1,6 @@
+Test3.java:14:1: compiler.err.types.incompatible.diff.ret: B, A, m()
+Test3.java:19:1: compiler.err.types.incompatible.diff.ret: D, C, m()
+Test3.java:27:1: compiler.err.types.incompatible.diff.ret: E<T>, B, m()
+Test3.java:33:1: compiler.err.types.incompatible.diff.ret: F<V>, E<U>, m()
+Test3.java:37:1: compiler.err.types.incompatible.diff.ret: F<V>, E<U>, m()
+5 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/rawOverride/7157798/Test4.java Fri Jun 08 12:45:43 2012 -0700
@@ -0,0 +1,29 @@
+/**
+ * @test /nodynamiccopyright/
+ * @bug 7062745 7157798
+ * @summary Negative test of conflicting same-name methods inherited from multiple interfaces when parameter types not compatible
+ * @compile/fail/ref=Test4.out -Werror -Xlint:unchecked -XDrawDiagnostics Test4.java
+ */
+
+import java.util.Set;
+import java.util.HashSet;
+
+interface A { void m(Set<Integer> s); }
+interface B { void m(Set<String> s); }
+interface C { void m(Set<?> s); }
+
+interface AB extends A, B {} //error
+
+interface AC extends A, C {} //error
+
+interface D<T> { void m(Set<T> s); }
+
+interface AD extends A, D<Integer> {} //OK
+
+interface AD2 extends A, D<Number> {} //error
+
+interface CD<T> extends C, D<T> {} //error
+
+interface E { <T> void m(Set<T> s); }
+
+interface DE<T> extends D<T>, E {} //error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/rawOverride/7157798/Test4.out Fri Jun 08 12:45:43 2012 -0700
@@ -0,0 +1,6 @@
+Test4.java:15:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set<java.lang.String>), B, m(java.util.Set<java.lang.Integer>), A
+Test4.java:17:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set<?>), C, m(java.util.Set<java.lang.Integer>), A
+Test4.java:23:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set<T>), D, m(java.util.Set<java.lang.Integer>), A
+Test4.java:25:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set<T>), D, m(java.util.Set<?>), C
+Test4.java:29:1: compiler.err.name.clash.same.erasure.no.override: <T>m(java.util.Set<T>), E, m(java.util.Set<T>), D
+5 errors
--- a/langtools/test/tools/javac/varargs/6313164/T6313164.out Thu Jun 07 12:10:41 2012 -0700
+++ b/langtools/test/tools/javac/varargs/6313164/T6313164.out Fri Jun 08 12:45:43 2012 -0700
@@ -1,6 +1,6 @@
T6313164.java:12:8: compiler.err.cant.apply.symbol.1: kindname.method, foo1, p1.A[], p1.B,p1.B, kindname.class, p1.B, (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164)
-T6313164.java:14:13: compiler.err.prob.found.req.1: (compiler.misc.invalid.inferred.types: X, (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164))
-T6313164.java:15:13: compiler.err.prob.found.req.1: (compiler.misc.invalid.inferred.types: X, (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164))
+T6313164.java:14:13: compiler.err.cant.apply.symbol.1: kindname.method, foo3, X[], compiler.misc.type.null,compiler.misc.type.null, kindname.class, p1.B, (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164)
+T6313164.java:15:13: compiler.err.cant.apply.symbol.1: kindname.method, foo4, X[], compiler.misc.type.null,compiler.misc.type.null, kindname.class, p1.B, (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164)
- compiler.note.unchecked.filename: B.java
- compiler.note.unchecked.recompile
3 errors