changeset 3040:e6fcc24b6d14

8132535: Compiler fails with diamond anonymous class creation with intersection bound of enclosing class Reviewed-by: mcimadamore
author sadayapalam
date Thu, 01 Oct 2015 19:47:06 +0530
parents 2fd864f1ff3a
children 37b60162a2db
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java test/tools/javac/generics/diamond/neg/Neg21.java test/tools/javac/generics/diamond/neg/Neg21.out test/tools/javac/generics/diamond/neg/Neg22.java test/tools/javac/generics/diamond/neg/Neg22.out test/tools/javac/generics/diamond/neg/Neg23.java test/tools/javac/generics/diamond/neg/Neg23.out test/tools/javac/generics/diamond/neg/pkg/Neg23_01.java
diffstat 8 files changed, 90 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Tue Sep 29 21:22:35 2015 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Thu Oct 01 19:47:06 2015 +0530
@@ -808,7 +808,7 @@
      */
     List<Type> checkDiamondDenotable(ClassType t) {
         ListBuffer<Type> buf = new ListBuffer<>();
-        for (Type arg : t.getTypeArguments()) {
+        for (Type arg : t.allparams()) {
             if (!diamondTypeChecker.visit(arg, null)) {
                 buf.append(arg);
             }
@@ -831,7 +831,7 @@
                 if (t.isCompound()) {
                     return false;
                 }
-                for (Type targ : t.getTypeArguments()) {
+                for (Type targ : t.allparams()) {
                     if (!visit(targ, s)) {
                         return false;
                     }
@@ -842,13 +842,16 @@
             @Override
             public Boolean visitTypeVar(TypeVar t, Void s) {
                 /* Any type variable mentioned in the inferred type must have been declared as a type parameter
-                  (i.e cannot have been produced by capture conversion (5.1.10) or by inference (18.4)
+                  (i.e cannot have been produced by inference (18.4))
                 */
                 return t.tsym.owner.type.getTypeArguments().contains(t);
             }
 
             @Override
             public Boolean visitCapturedType(CapturedType t, Void s) {
+                /* Any type variable mentioned in the inferred type must have been declared as a type parameter
+                  (i.e cannot have been produced by capture conversion (5.1.10))
+                */
                 return false;
             }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/diamond/neg/Neg21.java	Thu Oct 01 19:47:06 2015 +0530
@@ -0,0 +1,15 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8132535
+ * @summary Compiler fails with diamond anonymous class creation with intersection bound of enclosing class.
+ * @compile/fail/ref=Neg21.out Neg21.java -XDrawDiagnostics
+ */
+
+public class Neg21 <T extends java.io.Serializable & Cloneable> {
+
+    class A <X>{}
+
+    public void foo(){
+        new Neg21<>().new A<>(){} ;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/diamond/neg/Neg21.out	Thu Oct 01 19:47:06 2015 +0530
@@ -0,0 +1,2 @@
+Neg21.java:13:28: compiler.err.cant.apply.diamond.1: (compiler.misc.diamond: Neg21.A), (compiler.misc.diamond.invalid.arg: java.lang.Object&java.io.Serializable&java.lang.Cloneable, (compiler.misc.diamond: Neg21.A))
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/diamond/neg/Neg22.java	Thu Oct 01 19:47:06 2015 +0530
@@ -0,0 +1,21 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8132535
+ * @summary Compiler fails with diamond anonymous class creation with intersection bound of enclosing class.
+ * @compile/fail/ref=Neg22.out Neg22.java -XDrawDiagnostics
+ */
+
+public class Neg22  {
+
+    class Outer<X extends Runnable & java.io.Serializable> {
+        class Inner<Y> { }
+    }
+
+    class Box<Z> {
+        Box(Z z) { }
+    }
+
+    {
+        new Box<>(new Outer<>().new Inner<>()) { };
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/diamond/neg/Neg22.out	Thu Oct 01 19:47:06 2015 +0530
@@ -0,0 +1,2 @@
+Neg22.java:19:16: compiler.err.cant.apply.diamond.1: (compiler.misc.diamond: Neg22.Box), (compiler.misc.diamond.invalid.arg: Neg22.Outer<java.lang.Object&java.io.Serializable&java.lang.Runnable>.Inner<java.lang.Object>, (compiler.misc.diamond: Neg22.Box))
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/diamond/neg/Neg23.java	Thu Oct 01 19:47:06 2015 +0530
@@ -0,0 +1,12 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8132535
+ * @summary Compiler fails with diamond anonymous class creation with intersection bound of enclosing class.
+ * @compile/fail/ref=Neg23.out Neg23.java -XDrawDiagnostics
+ */
+
+public class Neg23  {
+    {
+        new pkg.Neg23_01<>().new Inner<>();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/diamond/neg/Neg23.out	Thu Oct 01 19:47:06 2015 +0530
@@ -0,0 +1,2 @@
+Neg23.java:10:39: compiler.err.not.def.public.cant.access: pkg.Neg23_02, pkg
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/diamond/neg/pkg/Neg23_01.java	Thu Oct 01 19:47:06 2015 +0530
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+package pkg;
+
+public class Neg23_01<X extends Neg23_02> {
+    public class Inner<Y> { }
+}
+
+class Neg23_02 {}