6729401: Compiler error when using F-bounded generics with free type variables

Thu, 29 Jan 2009 12:19:14 +0000

author
mcimadamore
date
Thu, 29 Jan 2009 12:19:14 +0000
changeset 212
79f2f2c7d846
parent 211
4542977c959e
child 213
49281ea88125

6729401: Compiler error when using F-bounded generics with free type variables
Summary: Javac applies wrong substitution to recursive type-variable bounds
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/code/Types.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/6729401/T6729401.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Thu Jan 29 12:18:19 2009 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Thu Jan 29 12:19:14 2009 +0000
     1.3 @@ -2131,9 +2131,6 @@
     1.4                                    List<Type> to) {
     1.5          if (tvars.isEmpty())
     1.6              return tvars;
     1.7 -        if (tvars.tail.isEmpty())
     1.8 -            // fast common case
     1.9 -            return List.<Type>of(substBound((TypeVar)tvars.head, from, to));
    1.10          ListBuffer<Type> newBoundsBuf = lb();
    1.11          boolean changed = false;
    1.12          // calculate new bounds
    1.13 @@ -2173,8 +2170,14 @@
    1.14          Type bound1 = subst(t.bound, from, to);
    1.15          if (bound1 == t.bound)
    1.16              return t;
    1.17 -        else
    1.18 -            return new TypeVar(t.tsym, bound1, syms.botType);
    1.19 +        else {
    1.20 +            // create new type variable without bounds
    1.21 +            TypeVar tv = new TypeVar(t.tsym, null, syms.botType);
    1.22 +            // the new bound should use the new type variable in place
    1.23 +            // of the old
    1.24 +            tv.bound = subst(bound1, List.<Type>of(t), List.<Type>of(tv));
    1.25 +            return tv;
    1.26 +        }
    1.27      }
    1.28      // </editor-fold>
    1.29  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/generics/6729401/T6729401.java	Thu Jan 29 12:19:14 2009 +0000
     2.3 @@ -0,0 +1,46 @@
     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 6729401
    2.30 + *
    2.31 + * @summary  Compiler error when using F-bounded generics with free type variables
    2.32 + * @author Maurizio Cimadamore
    2.33 + * @compile T6729401.java
    2.34 + *
    2.35 + */
    2.36 +
    2.37 +class T6729401 {
    2.38 +
    2.39 +    interface I<U,W> {
    2.40 +        <T extends I<U,T>> void m(I<U,T> x);
    2.41 +    }
    2.42 +
    2.43 +    <X extends I<Object,X>,Y extends I<Object,Y>> void test(I<Object,X> x, I<Object,Y> y) {
    2.44 +        x.<Y>m(y);
    2.45 +        x.m(y);
    2.46 +        y.<X>m(x);
    2.47 +        y.m(x);
    2.48 +    }
    2.49 +}

mercurial