changeset 1744:94e67bed460d

8008708: Regression: separate compilation causes crash in wildcards inference logic Summary: Invalid use of WildcardType.bound in Types.removeWildcards Reviewed-by: jjg
author mcimadamore
date Fri, 22 Feb 2013 18:19:51 +0000
parents 8e82e4f225e4
children ccbe7ffdd867
files src/share/classes/com/sun/tools/javac/code/Types.java test/tools/javac/lambda/separate/Foo.java test/tools/javac/lambda/separate/Test.java
diffstat 3 files changed, 72 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/Types.java	Fri Feb 22 13:31:35 2013 +0000
+++ b/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/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/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->{});
+    }
+}