提交 96a45dad 编写于 作者: M mcimadamore

6946618: sqe test fails: javac/generics/NewOnTypeParm in pit jdk7 b91 in all platforms.

Summary: Bad cast to ClassType in the new diamond implementation fails if the target type of the instance creation expression is a type-variable
Reviewed-by: jjg
上级 d2cd9198
......@@ -1472,7 +1472,7 @@ public class Attr extends JCTree.Visitor {
// Attribute clazz expression and store
// symbol + type back into the attributed tree.
Type clazztype = attribType(clazz, env);
Pair<Scope,Scope> mapping = getSyntheticScopeMapping((ClassType)clazztype);
Pair<Scope,Scope> mapping = getSyntheticScopeMapping(clazztype);
if (!TreeInfo.isDiamond(tree)) {
clazztype = chk.checkClassType(
tree.clazz.pos(), clazztype, true);
......@@ -1640,9 +1640,10 @@ public class Attr extends JCTree.Visitor {
List<Type> argtypes,
List<Type> typeargtypes,
boolean reportErrors) {
if (clazztype.isErroneous()) {
//if the type of the instance creation expression is erroneous
//return the erroneous type itself
if (clazztype.isErroneous() || mapping == erroneousMapping) {
//if the type of the instance creation expression is erroneous,
//or something prevented us to form a valid mapping, return the
//(possibly erroneous) type unchanged
return clazztype;
}
else if (clazztype.isInterface()) {
......@@ -1740,7 +1741,10 @@ public class Attr extends JCTree.Visitor {
* inference. The inferred return type of the synthetic constructor IS
* the inferred type for the diamond operator.
*/
private Pair<Scope, Scope> getSyntheticScopeMapping(ClassType ctype) {
private Pair<Scope, Scope> getSyntheticScopeMapping(Type ctype) {
if (ctype.tag != CLASS) {
return erroneousMapping;
}
Pair<Scope, Scope> mapping =
new Pair<Scope, Scope>(ctype.tsym.members(), new Scope(ctype.tsym));
List<Type> typevars = ctype.tsym.type.getTypeArguments();
......@@ -1763,6 +1767,8 @@ public class Attr extends JCTree.Visitor {
return mapping;
}
private final Pair<Scope,Scope> erroneousMapping = new Pair<Scope,Scope>(null, null);
/** Make an attributed null check tree.
*/
public JCExpression makeNullCheck(JCExpression arg) {
......
/*
* @test /nodynamiccopyright/
* @bug 6946618
* @summary sqe test fails: javac/generics/NewOnTypeParm in pit jdk7 b91 in all platforms.
* @author mcimadamore
* @compile/fail/ref=T6946618a.out -XDrawDiagnostics T6946618a.java
*/
class T6946618a {
static class C<T> {
T makeT() {
return new T(); //error
}
}
static class D<S> {
C<S> makeC() {
return new C<S>(); //ok
}
}
}
T6946618a.java:12:20: compiler.err.type.found.req: (compiler.misc.type.parameter: T), (compiler.misc.type.req.class)
1 error
/*
* @test /nodynamiccopyright/
* @bug 6946618
* @summary sqe test fails: javac/generics/NewOnTypeParm in pit jdk7 b91 in all platforms.
* @author mcimadamore
* @compile/fail/ref=T6946618b.out -XDrawDiagnostics T6946618b.java
*/
class T6946618b {
static class C<T> {
T makeT() {
return new T<>(); //error
}
}
static class D<S> {
C<S> makeC() {
return new C<>(); //ok
}
}
}
T6946618b.java:12:20: compiler.err.type.found.req: (compiler.misc.type.parameter: T), (compiler.misc.type.req.class)
1 error
/*
* @test /nodynamiccopyright/
* @bug 6946618
* @summary sqe test fails: javac/generics/NewOnTypeParm in pit jdk7 b91 in all platforms.
* @author mcimadamore
* @compile/fail/ref=T6946618c.out -XDrawDiagnostics T6946618c.java
*/
class T6946618c {
static class C<T> { }
void test() {
C<?> c1 = new C<? extends String>();
C<?> c2 = new C<? super String>();
C<?> c3 = new C<?>();
}
}
T6946618c.java:13:24: compiler.err.type.found.req: ? extends java.lang.String, class or interface without bounds
T6946618c.java:14:24: compiler.err.type.found.req: ? super java.lang.String, class or interface without bounds
T6946618c.java:15:24: compiler.err.type.found.req: ?, class or interface without bounds
3 errors
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册