提交 a28bdc5e 编写于 作者: M mcimadamore

6840638: Project Coin: Improved Type Inference for Generic Instance Creation (aka 'diamond')

Summary: diamond operator implementation (simple approach)
Reviewed-by: jjg
上级 2a3132fa
......@@ -122,6 +122,9 @@ public enum Source {
public boolean allowGenerics() {
return compareTo(JDK1_5) >= 0;
}
public boolean allowDiamond() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowEnums() {
return compareTo(JDK1_5) >= 0;
}
......
......@@ -195,6 +195,21 @@ public class Attr extends JCTree.Visitor {
return owntype;
}
Type checkReturn(JCTree tree, Type owntype, int ownkind, int pkind, Type pt) {
if (owntype.tag != ERROR && pt.tag != METHOD && pt.tag != FORALL) {
if ((ownkind & ~pkind) == 0) {
owntype = chk.checkReturnType(tree.pos(), owntype, pt);
} else {
log.error(tree.pos(), "unexpected.type",
kindNames(pkind),
kindName(ownkind));
owntype = types.createErrorType(owntype);
}
}
tree.type = owntype;
return owntype;
}
/** Is given blank final variable assignable, i.e. in a scope where it
* may be assigned to even though it is final?
* @param v The blank final variable.
......@@ -413,7 +428,14 @@ public class Attr extends JCTree.Visitor {
/** Derived visitor method: attribute a type tree.
*/
Type attribType(JCTree tree, Env<AttrContext> env) {
Type result = attribTree(tree, env, TYP, Type.noType);
Type result = attribType(tree, env, Type.noType);
return result;
}
/** Derived visitor method: attribute a type tree.
*/
Type attribType(JCTree tree, Env<AttrContext> env, Type pt) {
Type result = attribTree(tree, env, TYP, pt);
return result;
}
......@@ -1357,7 +1379,7 @@ public class Attr extends JCTree.Visitor {
// Check that value of resulting type is admissible in the
// current context. Also, capture the return type
result = check(tree, capture(restype), VAL, pkind, pt);
result = checkReturn(tree, capture(restype), VAL, pkind, pt);
}
chk.validate(tree.typeargs, localEnv);
}
......@@ -1432,9 +1454,9 @@ public class Attr extends JCTree.Visitor {
// Attribute clazz expression and store
// symbol + type back into the attributed tree.
Type clazztype = chk.checkClassType(
tree.clazz.pos(), attribType(clazz, env), true);
Type clazztype = attribType(clazz, env);
chk.validate(clazz, localEnv);
clazztype = chk.checkNewClassType(clazz.pos(), clazztype, true, pt);
if (tree.encl != null) {
// We have to work in this case to store
// symbol + type back into the attributed tree.
......@@ -1539,7 +1561,9 @@ public class Attr extends JCTree.Visitor {
// ...
// }
if (Resolve.isStatic(env)) cdef.mods.flags |= STATIC;
clazz = TreeInfo.isDiamond(tree) ?
make.Type(clazztype)
: clazz;
if (clazztype.tsym.isInterface()) {
cdef.implementing = List.of(clazz);
} else {
......@@ -2522,7 +2546,7 @@ public class Attr extends JCTree.Visitor {
if (clazztype.tag == CLASS) {
List<Type> formals = clazztype.tsym.type.getTypeArguments();
if (actuals.length() == formals.length()) {
if (actuals.length() == formals.length() || actuals.isEmpty()) {
List<Type> a = actuals;
List<Type> f = formals;
while (a.nonEmpty()) {
......@@ -2548,7 +2572,18 @@ public class Attr extends JCTree.Visitor {
clazzOuter = site;
}
}
owntype = new ClassType(clazzOuter, actuals, clazztype.tsym);
if (actuals.nonEmpty()) {
owntype = new ClassType(clazzOuter, actuals, clazztype.tsym);
}
else if (TreeInfo.isDiamond(tree)) {
//a type apply with no explicit type arguments - diamond operator
//the result type is a forall F where F's tvars are the type-variables
//that will be inferred when F is checked against the expected type
List<Type> ftvars = clazztype.tsym.type.getTypeArguments();
List<Type> new_tvars = types.newInstances(ftvars);
clazztype = new ClassType(clazzOuter, new_tvars, clazztype.tsym);
owntype = new ForAll(new_tvars, clazztype);
}
} else {
if (formals.length() != 0) {
log.error(tree.pos(), "wrong.number.type.args",
......
......@@ -362,8 +362,6 @@ public class Check {
Type checkType(DiagnosticPosition pos, Type found, Type req) {
if (req.tag == ERROR)
return req;
if (found.tag == FORALL)
return instantiatePoly(pos, (ForAll)found, req, convertWarner(pos, found, req));
if (req.tag == NONE)
return found;
if (types.isAssignable(found, req, convertWarner(pos, found, req)))
......@@ -381,42 +379,50 @@ public class Check {
return typeError(pos, diags.fragment("incompatible.types"), found, req);
}
/** Instantiate polymorphic type to some prototype, unless
* prototype is `anyPoly' in which case polymorphic type
* is returned unchanged.
*/
Type instantiatePoly(DiagnosticPosition pos, ForAll t, Type pt, Warner warn) {
if (pt == Infer.anyPoly && complexInference) {
return t;
} else if (pt == Infer.anyPoly || pt.tag == NONE) {
Type newpt = t.qtype.tag <= VOID ? t.qtype : syms.objectType;
return instantiatePoly(pos, t, newpt, warn);
} else if (pt.tag == ERROR) {
return pt;
} else {
Type checkReturnType(DiagnosticPosition pos, Type found, Type req) {
if (found.tag == FORALL) {
try {
return infer.instantiateExpr(t, pt, warn);
return instantiatePoly(pos, (ForAll) found, req, convertWarner(pos, found, req));
} catch (Infer.NoInstanceException ex) {
if (ex.isAmbiguous) {
JCDiagnostic d = ex.getDiagnostic();
log.error(pos,
"undetermined.type" + (d!=null ? ".1" : ""),
t, d);
return types.createErrorType(pt);
"undetermined.type" + (d != null ? ".1" : ""),
found, d);
return types.createErrorType(req);
} else {
JCDiagnostic d = ex.getDiagnostic();
return typeError(pos,
diags.fragment("incompatible.types" + (d!=null ? ".1" : ""), d),
t, pt);
diags.fragment("incompatible.types" + (d != null ? ".1" : ""), d),
found, req);
}
} catch (Infer.InvalidInstanceException ex) {
JCDiagnostic d = ex.getDiagnostic();
log.error(pos, "invalid.inferred.types", t.tvars, d);
return types.createErrorType(pt);
log.error(pos, "invalid.inferred.types", ((ForAll)found).tvars, d);
return types.createErrorType(req);
}
} else {
return checkType(pos, found, req);
}
}
/** Instantiate polymorphic type to some prototype, unless
* prototype is `anyPoly' in which case polymorphic type
* is returned unchanged.
*/
Type instantiatePoly(DiagnosticPosition pos, ForAll t, Type pt, Warner warn) throws Infer.NoInstanceException {
if (pt == Infer.anyPoly && complexInference) {
return t;
} else if (pt == Infer.anyPoly || pt.tag == NONE) {
Type newpt = t.qtype.tag <= VOID ? t.qtype : syms.objectType;
return instantiatePoly(pos, t, newpt, warn);
} else if (pt.tag == ERROR) {
return pt;
} else {
return infer.instantiateExpr(t, pt, warn);
}
}
/** 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.
......@@ -538,6 +544,29 @@ public class Check {
return t;
}
/** Check that type is a valid type for a new expression. If the type contains
* some uninferred type variables, instantiate them exploiting the expected
* type.
*
* @param pos Position to be used for error reporting.
* @param t The type to be checked.
* @param noBounds True if type bounds are illegal here.
* @param pt Expected type (used with diamond operator)
*/
Type checkNewClassType(DiagnosticPosition pos, Type t, boolean noBounds, Type pt) {
if (t.tag == FORALL) {
try {
t = instantiatePoly(pos, (ForAll)t, pt, Warner.noWarnings);
}
catch (Infer.NoInstanceException ex) {
JCDiagnostic d = ex.getDiagnostic();
log.error(pos, "cant.apply.diamond", t.getTypeArguments(), d);
return types.createErrorType(pt);
}
}
return checkClassType(pos, t, noBounds);
}
/** Check that type is a reifiable class, interface or array type.
* @param pos Position to be used for error reporting.
* @param t The type to be checked.
......@@ -890,7 +919,8 @@ public class Check {
}
checkCapture(tree);
}
if (tree.type.tag == CLASS || tree.type.tag == FORALL) {
// Check that this type is either fully parameterized, or
// not parameterized at all.
if (tree.type.getEnclosingType().isRaw())
......
......@@ -131,6 +131,7 @@ public class JavacParser implements Parser {
this.allowForeach = source.allowForeach();
this.allowStaticImport = source.allowStaticImport();
this.allowAnnotations = source.allowAnnotations();
this.allowDiamond = source.allowDiamond();
this.allowTypeAnnotations = source.allowTypeAnnotations();
this.keepDocComments = keepDocComments;
if (keepDocComments)
......@@ -148,6 +149,10 @@ public class JavacParser implements Parser {
*/
boolean allowGenerics;
/** Switch: Should diamond operator be recognized?
*/
boolean allowDiamond;
/** Switch: Should varargs be recognized?
*/
boolean allowVarargs;
......@@ -194,6 +199,7 @@ public class JavacParser implements Parser {
static final int TYPE = 2;
static final int NOPARAMS = 4;
static final int TYPEARG = 8;
static final int DIAMOND = 16;
/** The current mode.
*/
......@@ -1326,6 +1332,11 @@ public class JavacParser implements Parser {
ListBuffer<JCExpression> args = lb();
if (S.token() == LT) {
S.nextToken();
if (S.token() == GT && (mode & DIAMOND) != 0) {
checkDiamond();
S.nextToken();
return List.nil();
}
args.append(((mode & EXPR) == 0) ? typeArgument() : parseType());
while (S.token() == COMMA) {
S.nextToken();
......@@ -1497,7 +1508,7 @@ public class JavacParser implements Parser {
t = F.AnnotatedType(newAnnotations, t);
int oldmode = mode;
mode = TYPE;
mode = TYPE | DIAMOND;
if (S.token() == LT) {
checkGenerics();
t = typeArguments(t);
......@@ -1547,8 +1558,11 @@ public class JavacParser implements Parser {
JCExpression innerCreator(int newpos, List<JCExpression> typeArgs, JCExpression encl) {
JCExpression t = toP(F.at(S.pos()).Ident(ident()));
if (S.token() == LT) {
int oldmode = mode;
mode |= DIAMOND;
checkGenerics();
t = typeArguments(t);
mode = oldmode;
}
return classCreatorRest(newpos, encl, typeArgs, t);
}
......@@ -3099,6 +3113,12 @@ public class JavacParser implements Parser {
}
}
void checkDiamond() {
if (!allowDiamond) {
log.error(S.pos(), "diamond.not.supported.in.source", source.name);
allowDiamond = true;
}
}
void checkGenerics() {
if (!allowGenerics) {
log.error(S.pos(), "generics.not.supported.in.source", source.name);
......
......@@ -1073,6 +1073,10 @@ compiler.err.cant.resolve.location.args.params=\
symbol: {0} <{2}>{1}({3})\n\
location: {4} {5}
compiler.err.cant.apply.diamond=\
diamond operator cannot infer types for {0};\n\
reason: {1}
## The following are all possible string for "kindname".
## They should be called whatever the JLS calls them after it been translated
## to the appropriate language.
......@@ -1205,6 +1209,10 @@ compiler.err.enums.not.supported.in.source=\
enums are not supported in -source {0}\n\
(use -source 5 or higher to enable enums)
compiler.err.diamond.not.supported.in.source=\
diamond operator is not supported in -source {0}\n\
(use -source 7 or higher to enable diamond operator)
########################################
# Diagnostics for where clause implementation
# used by the RichDiagnosticFormatter.
......
......@@ -204,6 +204,15 @@ public class TreeInfo {
return (JCMethodInvocation)exec.expr;
}
/** Return true if a tree represents a diamond new expr. */
public static boolean isDiamond(JCTree tree) {
switch(tree.getTag()) {
case JCTree.TYPEAPPLY: return ((JCTypeApply)tree).getTypeArguments().isEmpty();
case JCTree.NEWCLASS: return isDiamond(((JCNewClass)tree).clazz);
default: return false;
}
}
/** Return true if a tree represents the null literal. */
public static boolean isNull(JCTree tree) {
if (tree.getTag() != JCTree.LITERAL)
......
/*
* @test /nodynamiccopyright/
* @bug 6840638
*
* @summary Project Coin: Improved Type Inference for Generic Instance Creation (aka 'diamond')
* @author mcimadamore
* @compile/fail/ref=Neg01.out Neg01.java -source 1.7 -XDrawDiagnostics
*
*/
class Neg01<X extends Number> {
Neg01(X x) {}
<Z> Neg01(X x, Z z) {}
void test() {
Neg01<String> n1 = new Neg01<>(""); //new Foo<Integer> created
Neg01<? extends String> n2 = new Neg01<>(""); //new Foo<Integer> created
Neg01<?> n3 = new Neg01<>(""); //new Foo<Object> created
Neg01<? super String> n4 = new Neg01<>(""); //new Foo<Object> created
Neg01<String> n5 = new Neg01<>(""){}; //new Foo<Integer> created
Neg01<? extends String> n6 = new Neg01<>(""){}; //new Foo<Integer> created
Neg01<?> n7 = new Neg01<>(""){}; //new Foo<Object> created
Neg01<? super String> n8 = new Neg01<>(""){}; //new Foo<Object> created
Neg01<String> n9 = new Neg01<>("", ""); //new Foo<Integer> created
Neg01<? extends String> n10 = new Neg01<>("", ""); //new Foo<Integer> created
Neg01<?> n11 = new Neg01<>("", ""); //new Foo<Object> created
Foo<? super String> n12 = new Neg01<>("", ""); //new Foo<Object> created
Neg01<String> n13 = new Neg01<>("", ""){}; //new Foo<Integer> created
Neg01<? extends String> n14 = new Neg01<>("", ""){}; //new Foo<Integer> created
Neg01<?> n15 = new Neg01<>("", ""){}; //new Foo<Object> created
Neg01<? super String> n16 = new Neg01<>("", ""){}; //new Foo<Object> created
}
}
Neg01.java:18:15: compiler.err.not.within.bounds: java.lang.String
Neg01.java:18:37: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<java.lang.String>)
Neg01.java:19:25: compiler.err.not.within.bounds: ? extends java.lang.String
Neg01.java:19:47: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
Neg01.java:20:23: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , java.lang.String, kindname.class, Neg01<java.lang.Number>
Neg01.java:21:23: compiler.err.not.within.bounds: ? super java.lang.String
Neg01.java:21:45: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<? super java.lang.String>)
Neg01.java:23:15: compiler.err.not.within.bounds: java.lang.String
Neg01.java:23:37: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<java.lang.String>)
Neg01.java:24:25: compiler.err.not.within.bounds: ? extends java.lang.String
Neg01.java:24:47: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
Neg01.java:25:23: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , java.lang.String, kindname.class, Neg01<java.lang.Number>
Neg01.java:25:38: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , , kindname.class, Neg01<java.lang.Number>
Neg01.java:26:23: compiler.err.not.within.bounds: ? super java.lang.String
Neg01.java:26:45: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<? super java.lang.String>)
Neg01.java:28:15: compiler.err.not.within.bounds: java.lang.String
Neg01.java:28:37: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<java.lang.String>)
Neg01.java:29:25: compiler.err.not.within.bounds: ? extends java.lang.String
Neg01.java:29:48: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
Neg01.java:30:24: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , java.lang.String,java.lang.String, kindname.class, Neg01<java.lang.Number>
Neg01.java:31:9: compiler.err.cant.resolve.location: kindname.class, Foo, , , kindname.class, Neg01<X>
Neg01.java:31:35: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , java.lang.String,java.lang.String, kindname.class, Neg01<java.lang.Number>
Neg01.java:33:15: compiler.err.not.within.bounds: java.lang.String
Neg01.java:33:38: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<java.lang.String>)
Neg01.java:34:25: compiler.err.not.within.bounds: ? extends java.lang.String
Neg01.java:34:48: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
Neg01.java:35:24: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , java.lang.String,java.lang.String, kindname.class, Neg01<java.lang.Number>
Neg01.java:35:43: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , , kindname.class, Neg01<java.lang.Number>
Neg01.java:36:23: compiler.err.not.within.bounds: ? super java.lang.String
Neg01.java:36:46: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<? super java.lang.String>)
30 errors
/*
* @test /nodynamiccopyright/
* @bug 6840638
*
* @summary Project Coin: Improved Type Inference for Generic Instance Creation (aka 'diamond')
* @author mcimadamore
* @compile/fail/ref=Neg02.out Neg02.java -source 1.7 -XDrawDiagnostics
*
*/
class Neg02 {
static class Foo<X extends Number> {
Foo(X x) {}
<Z> Foo(X x, Z z) {}
}
void testSimple() {
Foo<String> f1 = new Foo<>(""); //new Foo<Integer> created
Foo<? extends String> f2 = new Foo<>(""); //new Foo<Integer> created
Foo<?> f3 = new Foo<>(""); //new Foo<Object> created
Foo<? super String> f4 = new Foo<>(""); //new Foo<Object> created
Foo<String> f5 = new Foo<>(""){}; //new Foo<Integer> created
Foo<? extends String> f6 = new Foo<>(""){}; //new Foo<Integer> created
Foo<?> f7 = new Foo<>(""){}; //new Foo<Object> created
Foo<? super String> f8 = new Foo<>(""){}; //new Foo<Object> created
Foo<String> f9 = new Foo<>("", ""); //new Foo<Integer> created
Foo<? extends String> f10 = new Foo<>("", ""); //new Foo<Integer> created
Foo<?> f11 = new Foo<>("", ""); //new Foo<Object> created
Foo<? super String> f12 = new Foo<>("", ""); //new Foo<Object> created
Foo<String> f13 = new Foo<>("", ""){}; //new Foo<Integer> created
Foo<? extends String> f14 = new Foo<>("", ""){}; //new Foo<Integer> created
Foo<?> f15 = new Foo<>("", ""){}; //new Foo<Object> created
Foo<? super String> f16 = new Foo<>("", ""){}; //new Foo<Object> created
}
void testQualified() {
Foo<String> f1 = new Neg02.Foo<>(""); //new Foo<Integer> created
Foo<? extends String> f2 = new Neg02.Foo<>(""); //new Foo<Integer> created
Foo<?> f3 = new Neg02.Foo<>(""); //new Foo<Object> created
Foo<? super String> f4 = new Neg02.Foo<>(""); //new Foo<Object> created
Foo<String> f5 = new Neg02.Foo<>(""){}; //new Foo<Integer> created
Foo<? extends String> f6 = new Neg02.Foo<>(""){}; //new Foo<Integer> created
Foo<?> f7 = new Neg02.Foo<>(""){}; //new Foo<Object> created
Foo<? super String> f8 = new Neg02.Foo<>(""){}; //new Foo<Object> created
Foo<String> f9 = new Neg02.Foo<>("", ""); //new Foo<Integer> created
Foo<? extends String> f10 = new Neg02.Foo<>("", ""); //new Foo<Integer> created
Foo<?> f11 = new Neg02.Foo<>("", ""); //new Foo<Object> created
Foo<? super String> f12 = new Neg02.Foo<>("", ""); //new Foo<Object> created
Foo<String> f13 = new Neg02.Foo<>("", ""){}; //new Foo<Integer> created
Foo<? extends String> f14 = new Neg02.Foo<>("", ""){}; //new Foo<Integer> created
Foo<?> f15 = new Neg02.Foo<>("", ""){}; //new Foo<Object> created
Foo<? super String> f16 = new Neg02.Foo<>("", ""){}; //new Foo<Object> created
}
}
Neg02.java:19:13: compiler.err.not.within.bounds: java.lang.String
Neg02.java:19:33: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>)
Neg02.java:20:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg02.java:20:43: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
Neg02.java:21:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg02.Foo<java.lang.Number>
Neg02.java:22:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg02.java:22:41: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>)
Neg02.java:24:13: compiler.err.not.within.bounds: java.lang.String
Neg02.java:24:33: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>)
Neg02.java:25:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg02.java:25:43: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
Neg02.java:26:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg02.Foo<java.lang.Number>
Neg02.java:26:34: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg02.Foo<java.lang.Number>
Neg02.java:27:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg02.java:27:41: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>)
Neg02.java:29:13: compiler.err.not.within.bounds: java.lang.String
Neg02.java:29:33: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>)
Neg02.java:30:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg02.java:30:44: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
Neg02.java:31:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg02.Foo<java.lang.Number>
Neg02.java:32:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg02.java:32:42: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>)
Neg02.java:34:13: compiler.err.not.within.bounds: java.lang.String
Neg02.java:34:34: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>)
Neg02.java:35:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg02.java:35:44: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
Neg02.java:36:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg02.Foo<java.lang.Number>
Neg02.java:36:39: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg02.Foo<java.lang.Number>
Neg02.java:37:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg02.java:37:42: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>)
Neg02.java:41:13: compiler.err.not.within.bounds: java.lang.String
Neg02.java:41:39: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>)
Neg02.java:42:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg02.java:42:49: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
Neg02.java:43:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg02.Foo<java.lang.Number>
Neg02.java:44:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg02.java:44:47: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>)
Neg02.java:46:13: compiler.err.not.within.bounds: java.lang.String
Neg02.java:46:39: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>)
Neg02.java:47:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg02.java:47:49: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
Neg02.java:48:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg02.Foo<java.lang.Number>
Neg02.java:48:40: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg02.Foo<java.lang.Number>
Neg02.java:49:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg02.java:49:47: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>)
Neg02.java:51:13: compiler.err.not.within.bounds: java.lang.String
Neg02.java:51:39: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>)
Neg02.java:52:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg02.java:52:50: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
Neg02.java:53:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg02.Foo<java.lang.Number>
Neg02.java:54:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg02.java:54:48: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>)
Neg02.java:56:13: compiler.err.not.within.bounds: java.lang.String
Neg02.java:56:40: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>)
Neg02.java:57:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg02.java:57:50: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number)
Neg02.java:58:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg02.Foo<java.lang.Number>
Neg02.java:58:45: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg02.Foo<java.lang.Number>
Neg02.java:59:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg02.java:59:48: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>)
60 errors
/*
* @test /nodynamiccopyright/
* @bug 6840638
*
* @summary Project Coin: Improved Type Inference for Generic Instance Creation (aka 'diamond')
* @author mcimadamore
* @compile/fail/ref=Neg03.out Neg03.java -source 1.7 -XDrawDiagnostics
*
*/
class Neg03<U> {
class Foo<V extends Number> {
Foo(V x) {}
<Z> Foo(V x, Z z) {}
}
void testSimple() {
Foo<String> f1 = new Foo<>(""); //new Foo<Integer> created
Foo<? extends String> f2 = new Foo<>(""); //new Foo<Integer> created
Foo<?> f3 = new Foo<>(""); //new Foo<Object> created
Foo<? super String> f4 = new Foo<>(""); //new Foo<Object> created
Foo<String> f5 = new Foo<>(""){}; //new Foo<Integer> created
Foo<? extends String> f6 = new Foo<>(""){}; //new Foo<Integer> created
Foo<?> f7 = new Foo<>(""){}; //new Foo<Object> created
Foo<? super String> f8 = new Foo<>(""){}; //new Foo<Object> created
Foo<String> f9 = new Foo<>("", ""); //new Foo<Integer> created
Foo<? extends String> f10 = new Foo<>("", ""); //new Foo<Integer> created
Foo<?> f11 = new Foo<>("", ""); //new Foo<Object> created
Foo<? super String> f12 = new Foo<>("", ""); //new Foo<Object> created
Foo<String> f13 = new Foo<>("", ""){}; //new Foo<Integer> created
Foo<? extends String> f14 = new Foo<>("", ""){}; //new Foo<Integer> created
Foo<?> f15 = new Foo<>("", ""){}; //new Foo<Object> created
Foo<? super String> f16 = new Foo<>("", ""){}; //new Foo<Object> created
}
void testQualified_1() {
Foo<String> f1 = new Neg03<U>.Foo<>(""); //new Foo<Integer> created
Foo<? extends String> f2 = new Neg03<U>.Foo<>(""); //new Foo<Integer> created
Foo<?> f3 = new Neg03<U>.Foo<>(""); //new Foo<Object> created
Foo<? super String> f4 = new Neg03<U>.Foo<>(""); //new Foo<Object> created
Foo<String> f5 = new Neg03<U>.Foo<>(""){}; //new Foo<Integer> created
Foo<? extends String> f6 = new Neg03<U>.Foo<>(""){}; //new Foo<Integer> created
Foo<?> f7 = new Neg03<U>.Foo<>(""){}; //new Foo<Object> created
Foo<? super String> f8 = new Neg03<U>.Foo<>(""){}; //new Foo<Object> created
Foo<String> f9 = new Neg03<U>.Foo<>("", ""); //new Foo<Integer> created
Foo<? extends String> f10 = new Neg03<U>.Foo<>("", ""); //new Foo<Integer> created
Foo<?> f11 = new Neg03<U>.Foo<>("", ""); //new Foo<Object> created
Foo<? super String> f12 = new Neg03<U>.Foo<>("", ""); //new Foo<Object> created
Foo<String> f13 = new Neg03<U>.Foo<>("", ""){}; //new Foo<Integer> created
Foo<? extends String> f14 = new Neg03<U>.Foo<>("", ""){}; //new Foo<Integer> created
Foo<?> f15 = new Neg03<U>.Foo<>("", ""){}; //new Foo<Object> created
Foo<? super String> f16 = new Neg03<U>.Foo<>("", ""){}; //new Foo<Object> created
}
void testQualified_2(Neg03<U> n) {
Foo<String> f1 = n.new Foo<>(""); //new Foo<Integer> created
Foo<? extends String> f2 = n.new Foo<>(""); //new Foo<Integer> created
Foo<?> f3 = n.new Foo<>(""); //new Foo<Integer> created
Foo<? super String> f4 = n.new Foo<>(""); //new Foo<Integer> created
Foo<String> f5 = n.new Foo<>(""){}; //new Foo<Integer> created
Foo<? extends String> f6 = n.new Foo<>(""){}; //new Foo<Integer> created
Foo<?> f7 = n.new Foo<>(""){}; //new Foo<Integer> created
Foo<? super String> f8 = n.new Foo<>(""){}; //new Foo<Integer> created
Foo<String> f9 = n.new Foo<>("", ""); //new Foo<Integer> created
Foo<? extends String> f10 = n.new Foo<>("", ""); //new Foo<Integer> created
Foo<?> f11 = n.new Foo<>("", ""); //new Foo<Integer> created
Foo<? super String> f12 = n.new Foo<>("", ""); //new Foo<Integer> created
Foo<String> f13 = n.new Foo<>("", ""){}; //new Foo<Integer> created
Foo<? extends String> f14 = n.new Foo<>("", ""){}; //new Foo<Integer> created
Foo<?> f15 = n.new Foo<>("", ""){}; //new Foo<Integer> created
Foo<? super String> f16 = n.new Foo<>("", ""){}; //new Foo<Integer> created
}
}
Neg03.java:19:13: compiler.err.not.within.bounds: java.lang.String
Neg03.java:19:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
Neg03.java:20:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg03.java:20:43: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
Neg03.java:21:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:22:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg03.java:22:41: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
Neg03.java:24:13: compiler.err.not.within.bounds: java.lang.String
Neg03.java:24:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
Neg03.java:25:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg03.java:25:43: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
Neg03.java:26:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:26:34: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:27:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg03.java:27:41: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
Neg03.java:29:13: compiler.err.not.within.bounds: java.lang.String
Neg03.java:29:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
Neg03.java:30:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg03.java:30:44: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
Neg03.java:31:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:32:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg03.java:32:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
Neg03.java:34:13: compiler.err.not.within.bounds: java.lang.String
Neg03.java:34:34: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
Neg03.java:35:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg03.java:35:44: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
Neg03.java:36:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:36:39: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:37:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg03.java:37:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
Neg03.java:41:13: compiler.err.not.within.bounds: java.lang.String
Neg03.java:41:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
Neg03.java:42:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg03.java:42:52: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
Neg03.java:43:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:44:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg03.java:44:50: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
Neg03.java:46:13: compiler.err.not.within.bounds: java.lang.String
Neg03.java:46:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
Neg03.java:47:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg03.java:47:52: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
Neg03.java:48:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:48:43: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:49:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg03.java:49:50: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
Neg03.java:51:13: compiler.err.not.within.bounds: java.lang.String
Neg03.java:51:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
Neg03.java:52:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg03.java:52:53: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
Neg03.java:53:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:54:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg03.java:54:51: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
Neg03.java:56:13: compiler.err.not.within.bounds: java.lang.String
Neg03.java:56:43: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
Neg03.java:57:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg03.java:57:53: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
Neg03.java:58:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:58:48: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:59:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg03.java:59:51: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
Neg03.java:63:13: compiler.err.not.within.bounds: java.lang.String
Neg03.java:63:28: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
Neg03.java:64:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg03.java:64:38: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
Neg03.java:65:23: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:66:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg03.java:66:36: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
Neg03.java:68:13: compiler.err.not.within.bounds: java.lang.String
Neg03.java:68:28: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
Neg03.java:69:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg03.java:69:38: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
Neg03.java:70:23: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:70:36: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:71:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg03.java:71:36: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
Neg03.java:73:13: compiler.err.not.within.bounds: java.lang.String
Neg03.java:73:28: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
Neg03.java:74:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg03.java:74:39: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
Neg03.java:75:24: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:76:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg03.java:76:37: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
Neg03.java:78:13: compiler.err.not.within.bounds: java.lang.String
Neg03.java:78:29: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>)
Neg03.java:79:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg03.java:79:39: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
Neg03.java:80:24: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:80:41: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number>
Neg03.java:81:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg03.java:81:37: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>)
90 errors
/*
* @test /nodynamiccopyright/
* @bug 6840638
*
* @summary Project Coin: Improved Type Inference for Generic Instance Creation (aka 'diamond')
* @author mcimadamore
* @compile/fail/ref=Neg04.out Neg04.java -source 1.7 -XDrawDiagnostics
*
*/
class Neg04 {
void test() {
class Foo<V extends Number> {
Foo(V x) {}
<Z> Foo(V x, Z z) {}
}
Foo<String> n1 = new Foo<>(""); //new Foo<Integer> created
Foo<? extends String> n2 = new Foo<>(""); //new Foo<Integer> created
Foo<?> n3 = new Foo<>(""); //new Foo<Object> created
Foo<? super String> n4 = new Foo<>(""); //new Foo<Object> created
Foo<String> n5 = new Foo<>(""){}; //new Foo<Integer> created
Foo<? extends String> n6 = new Foo<>(""){}; //new Foo<Integer> created
Foo<?> n7 = new Foo<>(""){}; //new Foo<Object> created
Foo<? super String> n8 = new Foo<>(""){}; //new Foo<Object> created
Foo<String> n9 = new Foo<>("", ""); //new Foo<Integer> created
Foo<? extends String> n10 = new Foo<>("", ""); //new Foo<Integer> created
Foo<?> n11 = new Foo<>("", ""); //new Foo<Object> created
Foo<? super String> n12 = new Foo<>("", ""); //new Foo<Object> created
Foo<String> n13 = new Foo<>("", ""){}; //new Foo<Integer> created
Foo<? extends String> n14 = new Foo<>("", ""){}; //new Foo<Integer> created
Foo<?> n15 = new Foo<>("", ""){}; //new Foo<Object> created
Foo<? super String> n16 = new Foo<>("", ""){}; //new Foo<Object> created
}
}
Neg04.java:18:13: compiler.err.not.within.bounds: java.lang.String
Neg04.java:18:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<java.lang.String>)
Neg04.java:19:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg04.java:19:43: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
Neg04.java:20:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Foo<java.lang.Number>
Neg04.java:21:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg04.java:21:41: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<? super java.lang.String>)
Neg04.java:23:13: compiler.err.not.within.bounds: java.lang.String
Neg04.java:23:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<java.lang.String>)
Neg04.java:24:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg04.java:24:43: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
Neg04.java:25:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Foo<java.lang.Number>
Neg04.java:25:34: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Foo<java.lang.Number>
Neg04.java:26:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg04.java:26:41: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<? super java.lang.String>)
Neg04.java:28:13: compiler.err.not.within.bounds: java.lang.String
Neg04.java:28:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<java.lang.String>)
Neg04.java:29:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg04.java:29:44: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
Neg04.java:30:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Foo<java.lang.Number>
Neg04.java:31:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg04.java:31:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<? super java.lang.String>)
Neg04.java:33:13: compiler.err.not.within.bounds: java.lang.String
Neg04.java:33:34: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<java.lang.String>)
Neg04.java:34:23: compiler.err.not.within.bounds: ? extends java.lang.String
Neg04.java:34:44: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number)
Neg04.java:35:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Foo<java.lang.Number>
Neg04.java:35:39: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Foo<java.lang.Number>
Neg04.java:36:21: compiler.err.not.within.bounds: ? super java.lang.String
Neg04.java:36:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<? super java.lang.String>)
30 errors
/*
* @test /nodynamiccopyright/
* @bug 6840638
*
* @summary Project Coin: Improved Type Inference for Generic Instance Creation (aka 'diamond')
* @author mcimadamore
* @compile/fail/ref=Neg05.out Neg05.java -source 1.7 -XDrawDiagnostics
*
*/
class Neg05<U> {
class Foo<V> {
Foo(V x) {}
<Z> Foo(V x, Z z) {}
}
void testRare_1() {
Neg05<?>.Foo<String> f1 = new Neg05.Foo<>(""); //new Foo<Integer> created
Neg05<?>.Foo<? extends String> f2 = new Neg05.Foo<>(""); //new Foo<Integer> created
Neg05<?>.Foo<?> f3 = new Neg05.Foo<>(""); //new Foo<Object> created
Neg05<?>.Foo<? super String> f4 = new Neg05.Foo<>(""); //new Foo<Object> created
Neg05<?>.Foo<String> f5 = new Neg05.Foo<>(""){}; //new Foo<Integer> created
Neg05<?>.Foo<? extends String> f6 = new Neg05.Foo<>(""){}; //new Foo<Integer> created
Neg05<?>.Foo<?> f7 = new Neg05.Foo<>(""){}; //new Foo<Object> created
Neg05<?>.Foo<? super String> f8 = new Neg05.Foo<>(""){}; //new Foo<Object> created
Neg05<?>.Foo<String> f9 = new Neg05.Foo<>("", ""); //new Foo<Integer> created
Neg05<?>.Foo<? extends String> f10 = new Neg05.Foo<>("", ""); //new Foo<Integer> created
Neg05<?>.Foo<?> f11 = new Neg05.Foo<>("", ""); //new Foo<Object> created
Neg05<?>.Foo<? super String> f12 = new Neg05.Foo<>("", ""); //new Foo<Object> created
Neg05<?>.Foo<String> f13 = new Neg05.Foo<>("", ""){}; //new Foo<Integer> created
Neg05<?>.Foo<? extends String> f14 = new Neg05.Foo<>("", ""){}; //new Foo<Integer> created
Neg05<?>.Foo<?> f15 = new Neg05.Foo<>("", ""){}; //new Foo<Object> created
Neg05<?>.Foo<? super String> f16 = new Neg05.Foo<>("", ""){}; //new Foo<Object> created
}
void testRare_2(Neg05 n) {
Neg05<?>.Foo<String> f1 = n.new Foo<>(""); //new Foo<Integer> created
Neg05<?>.Foo<? extends String> f2 = n.new Foo<>(""); //new Foo<Integer> created
Neg05<?>.Foo<?> f3 = n.new Foo<>(""); //new Foo<Integer> created
Neg05<?>.Foo<? super String> f4 = n.new Foo<>(""); //new Foo<Integer> created
Neg05<?>.Foo<String> f5 = n.new Foo<>(""){}; //new Foo<Integer> created
Neg05<?>.Foo<? extends String> f6 = n.new Foo<>(""){}; //new Foo<Integer> created
Neg05<?>.Foo<?> f7 = n.new Foo<>(""){}; //new Foo<Integer> created
Neg05<?>.Foo<? super String> f8 = n.new Foo<>(""){}; //new Foo<Integer> created
Neg05<?>.Foo<String> f9 = n.new Foo<>("", ""); //new Foo<Integer> created
Neg05<?>.Foo<? extends String> f10 = n.new Foo<>("", ""); //new Foo<Integer> created
Neg05<?>.Foo<?> f11 = n.new Foo<>("", ""); //new Foo<Integer> created
Neg05<?>.Foo<? super String> f12 = n.new Foo<>("", ""); //new Foo<Integer> created
Neg05<?>.Foo<String> f13 = n.new Foo<>("", ""){}; //new Foo<Integer> created
Neg05<?>.Foo<? extends String> f14 = n.new Foo<>("", ""){}; //new Foo<Integer> created
Neg05<?>.Foo<?> f15 = n.new Foo<>("", ""){}; //new Foo<Integer> created
Neg05<?>.Foo<? super String> f16 = n.new Foo<>("", ""){}; //new Foo<Integer> created
}
}
Neg05.java:19:48: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:20:58: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:21:43: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:22:56: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:24:48: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:25:58: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:26:43: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:27:56: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:29:48: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:30:59: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:31:44: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:32:57: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:34:49: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:35:59: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:36:44: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:37:57: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:41:37: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:42:47: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:43:32: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:44:45: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:46:37: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:47:47: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:48:32: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:49:45: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:51:37: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:52:48: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:53:33: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:54:46: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:56:38: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:57:48: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:58:33: compiler.err.improperly.formed.type.inner.raw.param
Neg05.java:59:46: compiler.err.improperly.formed.type.inner.raw.param
32 errors
/*
* @test /nodynamiccopyright/
* @bug 6840638
*
* @summary Project Coin: Improved Type Inference for Generic Instance Creation (aka 'diamond')
* @author mcimadamore
* @compile Pos01.java -source 1.7
* @run main Pos01
*
*/
public class Pos01<X> {
Pos01(X x) {}
<Z> Pos01(X x, Z z) {}
void test() {
Pos01<Integer> p1 = new Pos01<>(1); //new Foo<Integer> created
Pos01<? extends Integer> p2 = new Pos01<>(1); //new Foo<Integer> created
Pos01<?> p3 = new Pos01<>(1); //new Foo<Object> created
Pos01<? super Integer> p4 = new Pos01<>(1); //new Foo<Object> created
Pos01<Integer> p5 = new Pos01<>(1){}; //new Foo<Integer> created
Pos01<? extends Integer> p6 = new Pos01<>(1){}; //new Foo<Integer> created
Pos01<?> p7 = new Pos01<>(1){}; //new Foo<Object> created
Pos01<? super Integer> p8 = new Pos01<>(1){}; //new Foo<Object> created
Pos01<Integer> p9 = new Pos01<>(1, ""); //new Foo<Integer> created
Pos01<? extends Integer> p10 = new Pos01<>(1, ""); //new Foo<Integer> created
Pos01<?> p11 = new Pos01<>(1, ""); //new Foo<Object> created
Pos01<? super Integer> p12 = new Pos01<>(1, ""); //new Foo<Object> created
Pos01<Integer> p13 = new Pos01<>(1, ""){}; //new Foo<Integer> created
Pos01<? extends Integer> p14= new Pos01<>(1, ""){}; //new Foo<Integer> created
Pos01<?> p15 = new Pos01<>(1, ""){}; //new Foo<Object> created
Pos01<? super Integer> p16 = new Pos01<>(1, ""){}; //new Foo<Object> created
}
public static void main(String[] args) {
Pos01<String> p1 = new Pos01<>("");
p1.test();
}
}
/*
* @test /nodynamiccopyright/
* @bug 6840638
*
* @summary Project Coin: Improved Type Inference for Generic Instance Creation (aka 'diamond')
* @author mcimadamore
* @compile Pos02.java -source 1.7
* @run main Pos02
*/
public class Pos02 {
static class Foo<X> {
Foo(X x) {}
<Z> Foo(X x, Z z) {}
}
void testSimple() {
Foo<Integer> f1 = new Foo<>(1); //new Foo<Integer> created
Foo<? extends Integer> f2 = new Foo<>(1); //new Foo<Integer> created
Foo<?> f3 = new Foo<>(1); //new Foo<Object> created
Foo<? super Integer> f4 = new Foo<>(1); //new Foo<Object> created
Foo<Integer> f5 = new Foo<>(1){}; //new Foo<Integer> created
Foo<? extends Integer> f6 = new Foo<>(1){}; //new Foo<Integer> created
Foo<?> f7 = new Foo<>(1){}; //new Foo<Object> created
Foo<? super Integer> f8 = new Foo<>(1){}; //new Foo<Object> created
Foo<Integer> f9 = new Foo<>(1, ""); //new Foo<Integer> created
Foo<? extends Integer> f10 = new Foo<>(1, ""); //new Foo<Integer> created
Foo<?> f11 = new Foo<>(1, ""); //new Foo<Object> created
Foo<? super Integer> f12 = new Foo<>(1, ""); //new Foo<Object> created
Foo<Integer> f13 = new Foo<>(1, ""){}; //new Foo<Integer> created
Foo<? extends Integer> f14 = new Foo<>(1, ""){}; //new Foo<Integer> created
Foo<?> f15 = new Foo<>(1, ""){}; //new Foo<Object> created
Foo<? super Integer> f16 = new Foo<>(1, ""){}; //new Foo<Object> created
}
void testQualified() {
Foo<Integer> f1 = new Pos02.Foo<>(1); //new Foo<Integer> created
Foo<? extends Integer> f2 = new Pos02.Foo<>(1); //new Foo<Integer> created
Foo<?> f3 = new Pos02.Foo<>(1); //new Foo<Object> created
Foo<? super Integer> f4 = new Pos02.Foo<>(1); //new Foo<Object> created
Foo<Integer> f5 = new Pos02.Foo<>(1){}; //new Foo<Integer> created
Foo<? extends Integer> f6 = new Pos02.Foo<>(1){}; //new Foo<Integer> created
Foo<?> f7 = new Pos02.Foo<>(1){}; //new Foo<Object> created
Foo<? super Integer> f8 = new Pos02.Foo<>(1){}; //new Foo<Object> created
Foo<Integer> f9 = new Pos02.Foo<>(1, ""); //new Foo<Integer> created
Foo<? extends Integer> f10 = new Pos02.Foo<>(1, ""); //new Foo<Integer> created
Foo<?> f11 = new Pos02.Foo<>(1, ""); //new Foo<Object> created
Foo<? super Integer> f12 = new Pos02.Foo<>(1, ""); //new Foo<Object> created
Foo<Integer> f13 = new Pos02.Foo<>(1, ""){}; //new Foo<Integer> created
Foo<? extends Integer> f14 = new Pos02.Foo<>(1, ""){}; //new Foo<Integer> created
Foo<?> f15 = new Pos02.Foo<>(1, ""){}; //new Foo<Object> created
Foo<? super Integer> f16 = new Pos02.Foo<>(1, ""){}; //new Foo<Object> created
}
public static void main(String[] args) {
Pos02 p2 = new Pos02();
p2.testSimple();
p2.testQualified();
}
}
/*
* @test /nodynamiccopyright/
* @bug 6840638
*
* @summary Project Coin: Improved Type Inference for Generic Instance Creation (aka 'diamond')
* @author mcimadamore
* @compile Pos03.java -source 1.7
* @run main Pos03
*
*/
public class Pos03<U> {
class Foo<V> {
Foo(V x) {}
<Z> Foo(V x, Z z) {}
}
void testSimple() {
Foo<Integer> f1 = new Foo<>(1); //new Foo<Integer> created
Foo<? extends Integer> f2 = new Foo<>(1); //new Foo<Integer> created
Foo<?> f3 = new Foo<>(1); //new Foo<Object> created
Foo<? super Integer> f4 = new Foo<>(1); //new Foo<Object> created
Foo<Integer> f5 = new Foo<>(1){}; //new Foo<Integer> created
Foo<? extends Integer> f6 = new Foo<>(1){}; //new Foo<Integer> created
Foo<?> f7 = new Foo<>(1){}; //new Foo<Object> created
Foo<? super Integer> f8 = new Foo<>(1){}; //new Foo<Object> created
Foo<Integer> f9 = new Foo<>(1, ""); //new Foo<Integer> created
Foo<? extends Integer> f10 = new Foo<>(1, ""); //new Foo<Integer> created
Foo<?> f11 = new Foo<>(1, ""); //new Foo<Object> created
Foo<? super Integer> f12 = new Foo<>(1, ""); //new Foo<Object> created
Foo<Integer> f13 = new Foo<>(1, ""){}; //new Foo<Integer> created
Foo<? extends Integer> f14 = new Foo<>(1, ""){}; //new Foo<Integer> created
Foo<?> f15 = new Foo<>(1, ""){}; //new Foo<Object> created
Foo<? super Integer> f16 = new Foo<>(1, ""){}; //new Foo<Object> created
}
void testQualified_1() {
Foo<Integer> f1 = new Pos03<U>.Foo<>(1); //new Foo<Integer> created
Foo<? extends Integer> f2 = new Pos03<U>.Foo<>(1); //new Foo<Integer> created
Foo<?> f3 = new Pos03<U>.Foo<>(1); //new Foo<Object> created
Foo<? super Integer> f4 = new Pos03<U>.Foo<>(1); //new Foo<Object> created
Foo<Integer> f5 = new Pos03<U>.Foo<>(1){}; //new Foo<Integer> created
Foo<? extends Integer> f6 = new Pos03<U>.Foo<>(1){}; //new Foo<Integer> created
Foo<?> f7 = new Pos03<U>.Foo<>(1){}; //new Foo<Object> created
Foo<? super Integer> f8 = new Pos03<U>.Foo<>(1){}; //new Foo<Object> created
Foo<Integer> f9 = new Pos03<U>.Foo<>(1, ""); //new Foo<Integer> created
Foo<? extends Integer> f10 = new Pos03<U>.Foo<>(1, ""); //new Foo<Integer> created
Foo<?> f11 = new Pos03<U>.Foo<>(1, ""); //new Foo<Object> created
Foo<? super Integer> f12 = new Pos03<U>.Foo<>(1, ""); //new Foo<Object> created
Foo<Integer> f13 = new Pos03<U>.Foo<>(1, ""){}; //new Foo<Integer> created
Foo<? extends Integer> f14 = new Pos03<U>.Foo<>(1, ""){}; //new Foo<Integer> created
Foo<?> f15 = new Pos03<U>.Foo<>(1, ""){}; //new Foo<Object> created
Foo<? super Integer> f16 = new Pos03<U>.Foo<>(1, ""){}; //new Foo<Object> created
}
void testQualified_2(Pos03<U> p) {
Foo<Integer> f1 = p.new Foo<>(1); //new Foo<Integer> created
Foo<? extends Integer> f2 = p.new Foo<>(1); //new Foo<Integer> created
Foo<?> f3 = p.new Foo<>(1); //new Foo<Object> created
Foo<? super Integer> f4 = p.new Foo<>(1); //new Foo<Object> created
Foo<Integer> f5 = p.new Foo<>(1){}; //new Foo<Integer> created
Foo<? extends Integer> f6 = p.new Foo<>(1){}; //new Foo<Integer> created
Foo<?> f7 = p.new Foo<>(1){}; //new Foo<Object> created
Foo<? super Integer> f8 = p.new Foo<>(1){}; //new Foo<Object> created
Foo<Integer> f9 = p.new Foo<>(1, ""); //new Foo<Integer> created
Foo<? extends Integer> f10 = p.new Foo<>(1, ""); //new Foo<Integer> created
Foo<?> f11 = p.new Foo<>(1, ""); //new Foo<Object> created
Foo<? super Integer> f12 = p.new Foo<>(1, ""); //new Foo<Object> created
Foo<Integer> f13 = p.new Foo<>(1, ""){}; //new Foo<Integer> created
Foo<? extends Integer> f14 = p.new Foo<>(1, ""){}; //new Foo<Integer> created
Foo<?> f15 = p.new Foo<>(1, ""){}; //new Foo<Object> created
Foo<? super Integer> f16 = p.new Foo<>(1, ""){}; //new Foo<Object> created
}
public static void main(String[] args) {
Pos03<String> p3 = new Pos03<>();
p3.testSimple();
p3.testQualified_1();
p3.testQualified_2(p3);
}
}
/*
* @test /nodynamiccopyright/
* @bug 6840638
*
* @summary Project Coin: Improved Type Inference for Generic Instance Creation (aka 'diamond')
* @author mcimadamore
* @compile Pos04.java -source 1.7
* @run main Pos04
*
*/
public class Pos04<U> {
void test() {
class Foo<V> {
Foo(V x) {}
<Z> Foo(V x, Z z) {}
}
Foo<Integer> p1 = new Foo<>(1); //new Foo<Integer> created
Foo<? extends Integer> p2 = new Foo<>(1); //new Foo<Integer> created
Foo<?> p3 = new Foo<>(1); //new Foo<Object> created
Foo<? super Integer> p4 = new Foo<>(1); //new Foo<Object> created
Foo<Integer> p5 = new Foo<>(1){}; //new Foo<Integer> created
Foo<? extends Integer> p6 = new Foo<>(1){}; //new Foo<Integer> created
Foo<?> p7 = new Foo<>(1){}; //new Foo<Object> created
Foo<? super Integer> p8 = new Foo<>(1){}; //new Foo<Object> created
Foo<Integer> p9 = new Foo<>(1, ""); //new Foo<Integer> created
Foo<? extends Integer> p10 = new Foo<>(1, ""); //new Foo<Integer> created
Foo<?> p11 = new Foo<>(1, ""); //new Foo<Object> created
Foo<? super Integer> p12 = new Foo<>(1, ""); //new Foo<Object> created
Foo<Integer> p13 = new Foo<>(1, ""){}; //new Foo<Integer> created
Foo<? extends Integer> p14 = new Foo<>(1, ""){}; //new Foo<Integer> created
Foo<?> p15 = new Foo<>(1, ""){}; //new Foo<Object> created
Foo<? super Integer> p16 = new Foo<>(1, ""){}; //new Foo<Object> created
}
public static void main(String[] args) {
Pos04<String> p4 = new Pos04<>();
p4.test();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册