# HG changeset patch # User mcimadamore # Date 1361460303 0 # Node ID 7ac9242d2ca6b81e20e9c855bc196601934dd658 # Parent f4fdd53f8b3ef0d411f58a34708c71745d63bb2a 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 diff -r f4fdd53f8b3e -r 7ac9242d2ca6 src/share/classes/com/sun/tools/javac/code/Types.java --- 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); } diff -r f4fdd53f8b3e -r 7ac9242d2ca6 test/tools/javac/lambda/TargetType64.java --- /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 { + void m(X x); + } + + void g(Object o) { } + + void test() { + SAM s1 = (x)->{}; + SAM s2 = this::g; + } +}