diff --git a/src/share/classes/com/sun/tools/javac/comp/Attr.java b/src/share/classes/com/sun/tools/javac/comp/Attr.java index cf1cf2c7f053ab5149c11fd968f3bc36236ebeb4..3f776c51038e9803e88eeca6bef56d0e7c6b8440 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java @@ -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 mapping = getSyntheticScopeMapping((ClassType)clazztype); + Pair 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 argtypes, List 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 getSyntheticScopeMapping(ClassType ctype) { + private Pair getSyntheticScopeMapping(Type ctype) { + if (ctype.tag != CLASS) { + return erroneousMapping; + } Pair mapping = new Pair(ctype.tsym.members(), new Scope(ctype.tsym)); List typevars = ctype.tsym.type.getTypeArguments(); @@ -1763,6 +1767,8 @@ public class Attr extends JCTree.Visitor { return mapping; } + private final Pair erroneousMapping = new Pair(null, null); + /** Make an attributed null check tree. */ public JCExpression makeNullCheck(JCExpression arg) { diff --git a/test/tools/javac/generics/6946618/T6946618a.java b/test/tools/javac/generics/6946618/T6946618a.java new file mode 100644 index 0000000000000000000000000000000000000000..7ddabc21d4c587394b0355bea9e34af66ee78393 --- /dev/null +++ b/test/tools/javac/generics/6946618/T6946618a.java @@ -0,0 +1,21 @@ +/* + * @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 makeT() { + return new T(); //error + } + } + + static class D { + C makeC() { + return new C(); //ok + } + } +} diff --git a/test/tools/javac/generics/6946618/T6946618a.out b/test/tools/javac/generics/6946618/T6946618a.out new file mode 100644 index 0000000000000000000000000000000000000000..dfb46b49f3d667ac54a526cfa1bc78aa0fbeedd9 --- /dev/null +++ b/test/tools/javac/generics/6946618/T6946618a.out @@ -0,0 +1,2 @@ +T6946618a.java:12:20: compiler.err.type.found.req: (compiler.misc.type.parameter: T), (compiler.misc.type.req.class) +1 error diff --git a/test/tools/javac/generics/6946618/T6946618b.java b/test/tools/javac/generics/6946618/T6946618b.java new file mode 100644 index 0000000000000000000000000000000000000000..af600a92c4148b4d5e9ad60139710eeeef330d5f --- /dev/null +++ b/test/tools/javac/generics/6946618/T6946618b.java @@ -0,0 +1,21 @@ +/* + * @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 makeT() { + return new T<>(); //error + } + } + + static class D { + C makeC() { + return new C<>(); //ok + } + } +} diff --git a/test/tools/javac/generics/6946618/T6946618b.out b/test/tools/javac/generics/6946618/T6946618b.out new file mode 100644 index 0000000000000000000000000000000000000000..d5460848be55a8ce65adcdcc2678c26020c3c9b3 --- /dev/null +++ b/test/tools/javac/generics/6946618/T6946618b.out @@ -0,0 +1,2 @@ +T6946618b.java:12:20: compiler.err.type.found.req: (compiler.misc.type.parameter: T), (compiler.misc.type.req.class) +1 error diff --git a/test/tools/javac/generics/6946618/T6946618c.java b/test/tools/javac/generics/6946618/T6946618c.java new file mode 100644 index 0000000000000000000000000000000000000000..034ecb5e4fb5e9f047cec3c18bf46f768610668e --- /dev/null +++ b/test/tools/javac/generics/6946618/T6946618c.java @@ -0,0 +1,17 @@ +/* + * @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 { } + + void test() { + C c1 = new C(); + C c2 = new C(); + C c3 = new C(); + } +} diff --git a/test/tools/javac/generics/6946618/T6946618c.out b/test/tools/javac/generics/6946618/T6946618c.out new file mode 100644 index 0000000000000000000000000000000000000000..01da79b2cc9fe20a93ea7aa32207298ec8efe5c2 --- /dev/null +++ b/test/tools/javac/generics/6946618/T6946618c.out @@ -0,0 +1,4 @@ +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