6531075: Missing synthetic casts when accessing fields/methods of intersection types including type variables

Wed, 09 Apr 2008 13:19:01 +0100

author
mcimadamore
date
Wed, 09 Apr 2008 13:19:01 +0100
changeset 23
961ae2608114
parent 20
ddd77d1c1b49
child 24
d032d5090fd5

6531075: Missing synthetic casts when accessing fields/methods of intersection types including type variables
Summary: bug when javac generates code involving intersection types
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/comp/TransTypes.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/6531075/T6531075.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java	Thu Apr 03 18:01:55 2008 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java	Wed Apr 09 13:19:01 2008 +0100
     1.3 @@ -690,13 +690,15 @@
     1.4  
     1.5      public void visitSelect(JCFieldAccess tree) {
     1.6          Type t = tree.selected.type;
     1.7 -        if (t.isCompound() || (t.tag == TYPEVAR && t.getUpperBound().isCompound())) {
     1.8 +        while (t.tag == TYPEVAR)
     1.9 +            t = t.getUpperBound();
    1.10 +        if (t.isCompound()) {
    1.11              if ((tree.sym.flags() & IPROXY) != 0) {
    1.12                  tree.sym = ((MethodSymbol)tree.sym).
    1.13                      implemented((TypeSymbol)tree.sym.owner, types);
    1.14              }
    1.15              tree.selected = cast(
    1.16 -                translate(tree.selected, erasure(t)),
    1.17 +                translate(tree.selected, erasure(tree.selected.type)),
    1.18                  erasure(tree.sym.owner.type));
    1.19          } else
    1.20              tree.selected = translate(tree.selected, erasure(t));
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/generics/6531075/T6531075.java	Wed Apr 09 13:19:01 2008 +0100
     2.3 @@ -0,0 +1,66 @@
     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 6531075
    2.30 + *
    2.31 + * @summary Missing synthetic casts when accessing fields/methods of intersection types including type variables
    2.32 + * @author Maurizio Cimadamore
    2.33 + *
    2.34 + */
    2.35 +
    2.36 +
    2.37 +public class T6531075 {
    2.38 +
    2.39 +    static class A {
    2.40 +        void a() {}
    2.41 +    }
    2.42 +
    2.43 +    static interface I{
    2.44 +        void i();
    2.45 +    }
    2.46 +
    2.47 +    static class E extends A implements I{
    2.48 +        public void i() {}
    2.49 +    }
    2.50 +
    2.51 +    static class C<W extends A & I, T extends W>{
    2.52 +        T t;
    2.53 +        W w;
    2.54 +        C(W w, T t) {
    2.55 +            this.w = w;
    2.56 +            this.t = t;
    2.57 +        }
    2.58 +    }
    2.59 +
    2.60 +    public static void main(String... args) {
    2.61 +        C<E,E> c = new C<E,E>(new E(), new E());
    2.62 +        testMemberMethods(c);
    2.63 +    }
    2.64 +
    2.65 +    static void testMemberMethods(C<?, ?> arg) {
    2.66 +        arg.t.a();
    2.67 +        arg.t.i();
    2.68 +    }
    2.69 +}

mercurial