mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-21 11:34:38 +02:00
6548436: Incorrect inconvertible types error
Types.rewrite quantifiers should cope with captured type-variables properly Reviewed-by: jjg
This commit is contained in:
parent
b2ffad7180
commit
0408a1adae
5 changed files with 222 additions and 26 deletions
|
@ -3367,33 +3367,67 @@ public class Types {
|
||||||
* quantifiers) only
|
* quantifiers) only
|
||||||
*/
|
*/
|
||||||
private Type rewriteQuantifiers(Type t, boolean high, boolean rewriteTypeVars) {
|
private Type rewriteQuantifiers(Type t, boolean high, boolean rewriteTypeVars) {
|
||||||
ListBuffer<Type> from = new ListBuffer<Type>();
|
return new Rewriter(high, rewriteTypeVars).rewrite(t);
|
||||||
ListBuffer<Type> to = new ListBuffer<Type>();
|
}
|
||||||
adaptSelf(t, from, to);
|
|
||||||
ListBuffer<Type> rewritten = new ListBuffer<Type>();
|
class Rewriter extends UnaryVisitor<Type> {
|
||||||
List<Type> formals = from.toList();
|
|
||||||
boolean changed = false;
|
boolean high;
|
||||||
for (Type arg : to.toList()) {
|
boolean rewriteTypeVars;
|
||||||
Type bound;
|
|
||||||
if (rewriteTypeVars && arg.tag == TYPEVAR) {
|
Rewriter(boolean high, boolean rewriteTypeVars) {
|
||||||
TypeVar tv = (TypeVar)arg;
|
this.high = high;
|
||||||
bound = high ? tv.bound : syms.botType;
|
this.rewriteTypeVars = rewriteTypeVars;
|
||||||
} else {
|
}
|
||||||
bound = high ? upperBound(arg) : lowerBound(arg);
|
|
||||||
}
|
Type rewrite(Type t) {
|
||||||
Type newarg = bound;
|
ListBuffer<Type> from = new ListBuffer<Type>();
|
||||||
if (arg != bound) {
|
ListBuffer<Type> to = new ListBuffer<Type>();
|
||||||
changed = true;
|
adaptSelf(t, from, to);
|
||||||
newarg = high ? makeExtendsWildcard(bound, (TypeVar)formals.head)
|
ListBuffer<Type> rewritten = new ListBuffer<Type>();
|
||||||
: makeSuperWildcard(bound, (TypeVar)formals.head);
|
List<Type> formals = from.toList();
|
||||||
}
|
boolean changed = false;
|
||||||
rewritten.append(newarg);
|
for (Type arg : to.toList()) {
|
||||||
formals = formals.tail;
|
Type bound = visit(arg);
|
||||||
|
if (arg != bound) {
|
||||||
|
changed = true;
|
||||||
|
bound = high ? makeExtendsWildcard(bound, (TypeVar)formals.head)
|
||||||
|
: makeSuperWildcard(bound, (TypeVar)formals.head);
|
||||||
|
}
|
||||||
|
rewritten.append(bound);
|
||||||
|
formals = formals.tail;
|
||||||
|
}
|
||||||
|
if (changed)
|
||||||
|
return subst(t.tsym.type, from.toList(), rewritten.toList());
|
||||||
|
else
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type visitType(Type t, Void s) {
|
||||||
|
return high ? upperBound(t) : lowerBound(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type visitCapturedType(CapturedType t, Void s) {
|
||||||
|
return visitWildcardType(t.wildcard, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type visitTypeVar(TypeVar t, Void s) {
|
||||||
|
if (rewriteTypeVars)
|
||||||
|
return high ? t.bound : syms.botType;
|
||||||
|
else
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type visitWildcardType(WildcardType t, Void s) {
|
||||||
|
Type bound = high ? t.getExtendsBound() :
|
||||||
|
t.getSuperBound();
|
||||||
|
if (bound == null)
|
||||||
|
bound = high ? syms.objectType : syms.botType;
|
||||||
|
return bound;
|
||||||
}
|
}
|
||||||
if (changed)
|
|
||||||
return subst(t.tsym.type, from.toList(), rewritten.toList());
|
|
||||||
else
|
|
||||||
return t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
40
langtools/test/tools/javac/cast/6548436/T6548436a.java
Normal file
40
langtools/test/tools/javac/cast/6548436/T6548436a.java
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 6548436
|
||||||
|
* @summary Incorrect inconvertible types error
|
||||||
|
* @author Maurizio Cimadamore
|
||||||
|
*
|
||||||
|
* @compile T6548436a.java
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class T6548436a {
|
||||||
|
|
||||||
|
static class Base<E extends Comparable<E>> {}
|
||||||
|
|
||||||
|
static void test(Base<?> je) {
|
||||||
|
Object o = (Base<Integer>)je;
|
||||||
|
}
|
||||||
|
}
|
40
langtools/test/tools/javac/cast/6548436/T6548436b.java
Normal file
40
langtools/test/tools/javac/cast/6548436/T6548436b.java
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 6548436
|
||||||
|
* @summary Incorrect inconvertible types error
|
||||||
|
* @author Maurizio Cimadamore
|
||||||
|
*
|
||||||
|
* @compile T6548436b.java
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class T6548436b {
|
||||||
|
|
||||||
|
enum E { }
|
||||||
|
|
||||||
|
static void test(Enum<?> o) {
|
||||||
|
Object e = (E)o;
|
||||||
|
}
|
||||||
|
}
|
42
langtools/test/tools/javac/cast/6548436/T6548436c.java
Normal file
42
langtools/test/tools/javac/cast/6548436/T6548436c.java
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 6548436
|
||||||
|
* @summary Incorrect inconvertible types error
|
||||||
|
* @author Maurizio Cimadamore
|
||||||
|
*
|
||||||
|
* @compile T6548436c.java
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class T6548436c {
|
||||||
|
|
||||||
|
interface A<T extends A<? super T>> { }
|
||||||
|
|
||||||
|
interface B extends A<B> { }
|
||||||
|
|
||||||
|
static void test(A<?> a) {
|
||||||
|
Object o = (B)a;
|
||||||
|
}
|
||||||
|
}
|
40
langtools/test/tools/javac/cast/6548436/T6548436d.java
Normal file
40
langtools/test/tools/javac/cast/6548436/T6548436d.java
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 6548436
|
||||||
|
* @summary Incorrect inconvertible types error
|
||||||
|
* @author Maurizio Cimadamore
|
||||||
|
*
|
||||||
|
* @compile/fail T6548436d.java
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class T6548436d {
|
||||||
|
|
||||||
|
static class Base<E extends Comparable<E>> {}
|
||||||
|
|
||||||
|
static void test(Base<? extends Double> je) {
|
||||||
|
Object o = (Base<Integer>)je;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue