Wed, 09 Apr 2008 14:45:50 +0100
6450290: Capture of nested wildcards causes type error
Summary: A missing capture conversion makes javac to think that some expressions are well-formed even when they aren't
Reviewed-by: jjg
src/share/classes/com/sun/tools/javac/comp/Attr.java | file | annotate | diff | comparison | revisions | |
test/tools/javac/generics/wildcards/T6450290.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Apr 09 14:05:24 2008 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Apr 09 14:45:50 2008 +0100 1.3 @@ -1878,8 +1878,10 @@ 1.4 boolean varArgs = env.info.varArgs; 1.5 tree.sym = sym; 1.6 1.7 - if (site.tag == TYPEVAR && !isType(sym) && sym.kind != ERR) 1.8 - site = capture(site.getUpperBound()); 1.9 + if (site.tag == TYPEVAR && !isType(sym) && sym.kind != ERR) { 1.10 + while (site.tag == TYPEVAR) site = site.getUpperBound(); 1.11 + site = capture(site); 1.12 + } 1.13 1.14 // If that symbol is a variable, ... 1.15 if (sym.kind == VAR) {
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/generics/wildcards/T6450290.java Wed Apr 09 14:45:50 2008 +0100 2.3 @@ -0,0 +1,44 @@ 2.4 +/* 2.5 + * Copyright 2004-2006 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 6450290 2.30 + * @summary Capture of nested wildcards causes type error 2.31 + * @author Maurizio Cimadamore 2.32 + * @compile/fail T6450290.java 2.33 + */ 2.34 + 2.35 +public class T6450290 { 2.36 + static class Box<X extends Box<?,?>, T extends X> { 2.37 + T value; 2.38 + Box<X, T> same; 2.39 + } 2.40 + 2.41 + static class A extends Box<A,A> {} 2.42 + static class B extends Box<B,B> {} 2.43 + public static void main(String[] args) { 2.44 + Box<?,?> b = new Box<Box<A,A>,Box<A,A>>(); 2.45 + b.value.same = new Box<B,B>(); //javac misses this bad assignment 2.46 + } 2.47 +}