changeset 1737:7ac9242d2ca6

8008293: Declared bounds not considered when functional interface containing unbound wildcards is instantiated Summary: Wildcards inference should re-use some of the bounds info generated during capture conversion Reviewed-by: jjg
author mcimadamore
date Thu, 21 Feb 2013 15:25:03 +0000
parents f4fdd53f8b3e
children 9f0ec00514b6
files src/share/classes/com/sun/tools/javac/code/Types.java test/tools/javac/lambda/TargetType64.java
diffstat 2 files changed, 52 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/Types.java	Thu Feb 21 15:23:48 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Thu Feb 21 15:25:03 2013 +0000
@@ -580,7 +580,17 @@
             for (Type t : formalInterface.getTypeArguments()) {
                 if (actualTypeargs.head.hasTag(WILDCARD)) {
                     WildcardType wt = (WildcardType)actualTypeargs.head;
-                    typeargs.append(wt.type);
+                    Type bound;
+                    switch (wt.kind) {
+                        case UNBOUND:
+                            //use declared bound if it doesn't depend on formal type-args
+                            bound = wt.bound.bound.containsAny(formalInterface.getTypeArguments()) ?
+                                    syms.objectType : wt.bound.bound;
+                            break;
+                        default:
+                            bound = wt.type;
+                    }
+                    typeargs.append(bound);
                 } else {
                     typeargs.append(actualTypeargs.head);
                 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/TargetType64.java	Thu Feb 21 15:25:03 2013 +0000
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+/*
+ * @test
+ * @bug 8008293
+ * @summary Declared bounds not considered when functional interface containing unbound wildcards is instantiated
+ * @compile TargetType64.java
+ */
+class TargetType64 {
+    interface SAM<X extends Number> {
+        void m(X x);
+    }
+
+    void g(Object o) { }
+
+    void test() {
+        SAM<?> s1 = (x)->{};
+        SAM<?> s2 = this::g;
+    }
+}