6507024: casting an array to a generic type results in a 'capture#69 of ?' type error

Fri, 30 May 2008 10:42:43 +0100

author
mcimadamore
date
Fri, 30 May 2008 10:42:43 +0100
changeset 41
6e9a43815df7
parent 40
8852d96b593b
child 42
f7e64b33d5a4

6507024: casting an array to a generic type results in a 'capture#69 of ?' type error
Summary: Types.isSubtypeUnchecked() should handle type-variables subtyping properly
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/code/Types.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/T6507024.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Fri May 30 10:29:27 2008 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Fri May 30 10:42:43 2008 +0100
     1.3 @@ -301,7 +301,11 @@
     1.4                  : isSubtypeUnchecked(elemtype(t), elemtype(s), warn);
     1.5          } else if (isSubtype(t, s)) {
     1.6              return true;
     1.7 -        } else if (!s.isRaw()) {
     1.8 +        }
     1.9 +        else if (t.tag == TYPEVAR) {
    1.10 +            return isSubtypeUnchecked(t.getUpperBound(), s, warn);
    1.11 +        }
    1.12 +        else if (!s.isRaw()) {
    1.13              Type t2 = asSuper(t, s.tsym);
    1.14              if (t2 != null && t2.isRaw()) {
    1.15                  if (isReifiable(s))
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/generics/T6507024.java	Fri May 30 10:42:43 2008 +0100
     2.3 @@ -0,0 +1,37 @@
     2.4 +/*
     2.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    2.24 + * have any questions.
    2.25 + */
    2.26 +
    2.27 +/*
    2.28 + * @test
    2.29 + * @bug     6507024
    2.30 + * @summary unchecked conversion between arrays fails after capture conversion
    2.31 + * @author Maurizio Cimadamore
    2.32 + *
    2.33 + * @compile T6507024.java
    2.34 + */
    2.35 +
    2.36 +public class T6507024<T> {
    2.37 +    <Z> void m(T6507024<Z>[] results) {
    2.38 +        T6507024<Z>[] r = results.getClass().cast(null);
    2.39 +    }
    2.40 +}

mercurial