8008708: Regression: separate compilation causes crash in wildcards inference logic
authormcimadamore
Fri, 22 Feb 2013 18:19:51 +0000
changeset 16318 14906f8d3a42
parent 16317 1b4b06b67ea4
child 16319 e586bfeb39c5
8008708: Regression: separate compilation causes crash in wildcards inference logic Summary: Invalid use of WildcardType.bound in Types.removeWildcards Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/javac/code/Types.java
langtools/test/tools/javac/lambda/separate/Foo.java
langtools/test/tools/javac/lambda/separate/Test.java
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java	Fri Feb 22 13:31:35 2013 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java	Fri Feb 22 18:19:51 2013 +0000
@@ -572,20 +572,24 @@
     }
 
     public Type removeWildcards(Type site) {
-        if (capture(site) != site) {
+        Type capturedSite = capture(site);
+        if (capturedSite != site) {
             Type formalInterface = site.tsym.type;
             ListBuffer<Type> typeargs = ListBuffer.lb();
             List<Type> actualTypeargs = site.getTypeArguments();
+            List<Type> capturedTypeargs = capturedSite.getTypeArguments();
             //simply replace the wildcards with its bound
             for (Type t : formalInterface.getTypeArguments()) {
                 if (actualTypeargs.head.hasTag(WILDCARD)) {
                     WildcardType wt = (WildcardType)actualTypeargs.head;
                     Type bound;
                     switch (wt.kind) {
+                        case EXTENDS:
                         case UNBOUND:
+                            CapturedType capVar = (CapturedType)capturedTypeargs.head;
                             //use declared bound if it doesn't depend on formal type-args
-                            bound = wt.bound.bound.containsAny(formalInterface.getTypeArguments()) ?
-                                    syms.objectType : wt.bound.bound;
+                            bound = capVar.bound.containsAny(capturedSite.getTypeArguments()) ?
+                                    syms.objectType : capVar.bound;
                             break;
                         default:
                             bound = wt.type;
@@ -595,6 +599,7 @@
                     typeargs.append(actualTypeargs.head);
                 }
                 actualTypeargs = actualTypeargs.tail;
+                capturedTypeargs = capturedTypeargs.tail;
             }
             return subst(formalInterface, formalInterface.getTypeArguments(), typeargs.toList());
         } else {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/separate/Foo.java	Fri Feb 22 18:19:51 2013 +0000
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2013, 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.
+ */
+interface Foo<X extends Number> {
+    void m(X x);
+}
+
+class FooLib {
+    void m1(Foo<?> uf) { }
+    void m2(Foo<? extends Object> uf) { }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/separate/Test.java	Fri Feb 22 18:19:51 2013 +0000
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2012, 2013, 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.
+ */
+
+/*
+ * @test
+ * @compile Foo.java
+ * @compile Test.java
+ */
+class Test {
+    void test(FooLib fl) {
+        fl.m1(x->{});
+        fl.m2(x->{});
+    }
+}