提交 18851104 编写于 作者: M mcimadamore

8008540: Constructor reference to non-reifiable array should be rejected

8008539: Spurious error when constructor reference mention an interface type
8008538: Constructor reference accepts wildcard parameterized types
Summary: Overhaul of Check.checkConstructorRefType
Reviewed-by: jjg
上级 d3f574c7
......@@ -670,11 +670,18 @@ public class Check {
t = checkClassOrArrayType(pos, t);
if (t.hasTag(CLASS)) {
if ((t.tsym.flags() & (ABSTRACT | INTERFACE)) != 0) {
log.error(pos, "abstract.cant.be.instantiated");
log.error(pos, "abstract.cant.be.instantiated", t.tsym);
t = types.createErrorType(t);
} else if ((t.tsym.flags() & ENUM) != 0) {
log.error(pos, "enum.cant.be.instantiated");
t = types.createErrorType(t);
} else {
t = checkClassType(pos, t, true);
}
} else if (t.hasTag(ARRAY)) {
if (!types.isReifiable(((ArrayType)t).elemtype)) {
log.error(pos, "generic.array.creation");
t = types.createErrorType(t);
}
}
return t;
......
MethodReference38.java:24:18: compiler.err.abstract.cant.be.instantiated
MethodReference38.java:25:18: compiler.err.abstract.cant.be.instantiated
MethodReference38.java:26:18: compiler.err.abstract.cant.be.instantiated
MethodReference38.java:24:18: compiler.err.abstract.cant.be.instantiated: MethodReference38.A
MethodReference38.java:25:18: compiler.err.abstract.cant.be.instantiated: MethodReference38.I
MethodReference38.java:26:18: compiler.err.abstract.cant.be.instantiated: MethodReference38.AC
MethodReference38.java:27:18: compiler.err.enum.cant.be.instantiated
4 errors
/*
* @test /nodynamiccopyright/
* @bug 8008540 8008539 8008538
* @summary Constructor reference to non-reifiable array should be rejected
* @compile/fail/ref=MethodReference64.out -XDrawDiagnostics MethodReference64.java
*/
class MethodReference64 {
interface ClassFactory {
Object m();
}
interface ArrayFactory {
Object m(int i);
}
@interface Anno { }
enum E { }
interface I { }
static class Foo<X> { }
void m(ClassFactory cf) { }
void m(ArrayFactory cf) { }
void testAssign() {
ClassFactory c1 = Anno::new; //error
ClassFactory c2 = E::new; //error
ClassFactory c3 = I::new; //error
ClassFactory c4 = Foo<?>::new; //error
ClassFactory c5 = 1::new; //error
ArrayFactory a1 = Foo<?>[]::new; //ok
ArrayFactory a2 = Foo<? extends String>[]::new; //error
}
void testMethod() {
m(Anno::new); //error
m(E::new); //error
m(I::new); //error
m(Foo<?>::new); //error
m(1::new); //error
m(Foo<?>[]::new); //ok - resolves to m(ArrayFactory)
m(Foo<? extends String>[]::new); //error
}
}
MethodReference64.java:28:27: compiler.err.abstract.cant.be.instantiated: MethodReference64.Anno
MethodReference64.java:29:27: compiler.err.enum.cant.be.instantiated
MethodReference64.java:30:27: compiler.err.abstract.cant.be.instantiated: MethodReference64.I
MethodReference64.java:31:30: compiler.err.type.found.req: ?, (compiler.misc.type.req.exact)
MethodReference64.java:32:27: compiler.err.unexpected.type: kindname.class, kindname.value
MethodReference64.java:34:48: compiler.err.generic.array.creation
MethodReference64.java:38:11: compiler.err.abstract.cant.be.instantiated: MethodReference64.Anno
MethodReference64.java:39:11: compiler.err.enum.cant.be.instantiated
MethodReference64.java:40:11: compiler.err.abstract.cant.be.instantiated: MethodReference64.I
MethodReference64.java:41:14: compiler.err.type.found.req: ?, (compiler.misc.type.req.exact)
MethodReference64.java:42:11: compiler.err.unexpected.type: kindname.class, kindname.value
MethodReference64.java:44:32: compiler.err.generic.array.creation
12 errors
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册