8008708: Regression: separate compilation causes crash in wildcards inference logic
Invalid use of WildcardType.bound in Types.removeWildcards Reviewed-by: jjg
This commit is contained in:
parent
96495bc664
commit
7776fdebe7
@ -572,20 +572,24 @@ public class Types {
|
||||
}
|
||||
|
||||
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 @@ public class Types {
|
||||
typeargs.append(actualTypeargs.head);
|
||||
}
|
||||
actualTypeargs = actualTypeargs.tail;
|
||||
capturedTypeargs = capturedTypeargs.tail;
|
||||
}
|
||||
return subst(formalInterface, formalInterface.getTypeArguments(), typeargs.toList());
|
||||
} else {
|
||||
|
30
langtools/test/tools/javac/lambda/separate/Foo.java
Normal file
30
langtools/test/tools/javac/lambda/separate/Foo.java
Normal file
@ -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) { }
|
||||
}
|
34
langtools/test/tools/javac/lambda/separate/Test.java
Normal file
34
langtools/test/tools/javac/lambda/separate/Test.java
Normal file
@ -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->{});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user