Thu, 30 Jul 2009 10:30:10 +0100
6862608: rich diagnostic sometimes contain wrong type variable numbering
Summary: The rich formatter generates worng numbers for type-variables in where clauses
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Jul 30 10:29:53 2009 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Jul 30 10:30:10 2009 +0100 1.3 @@ -1003,7 +1003,7 @@ 1.4 inferred: {0}\n\ 1.5 bound(s): {1} 1.6 compiler.misc.inferred.do.not.conform.to.params=\ 1.7 - actual arguments do not conforms to inferred formal arguments\n\ 1.8 + actual arguments do not conform to inferred formal arguments\n\ 1.9 required: {0}\n\ 1.10 found: {1} 1.11
2.1 --- a/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Thu Jul 30 10:29:53 2009 +0100 2.2 +++ b/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Thu Jul 30 10:30:10 2009 +0100 2.3 @@ -208,6 +208,32 @@ 2.4 } 2.5 return clauses.reverse(); 2.6 } 2.7 + 2.8 + private int indexOf(Type type, WhereClauseKind kind) { 2.9 + int index = 1; 2.10 + for (Type t : whereClauses.get(kind).keySet()) { 2.11 + if (t.tsym == type.tsym) { 2.12 + return index; 2.13 + } 2.14 + if (kind != WhereClauseKind.TYPEVAR || 2.15 + t.toString().equals(type.toString())) { 2.16 + index++; 2.17 + } 2.18 + } 2.19 + return -1; 2.20 + } 2.21 + 2.22 + private boolean unique(TypeVar typevar) { 2.23 + int found = 0; 2.24 + for (Type t : whereClauses.get(WhereClauseKind.TYPEVAR).keySet()) { 2.25 + if (t.toString().equals(typevar.toString())) { 2.26 + found++; 2.27 + } 2.28 + } 2.29 + if (found < 1) 2.30 + throw new AssertionError("Missing type variable in where clause " + typevar); 2.31 + return found == 1; 2.32 + } 2.33 //where 2.34 /** 2.35 * This enum defines all posssible kinds of where clauses that can be 2.36 @@ -366,33 +392,6 @@ 2.37 } 2.38 } 2.39 2.40 - private int indexOf(Type type, WhereClauseKind kind) { 2.41 - int index = 0; 2.42 - boolean found = false; 2.43 - for (Type t : whereClauses.get(kind).keySet()) { 2.44 - if (t == type) { 2.45 - found = true; 2.46 - break; 2.47 - } 2.48 - index++; 2.49 - } 2.50 - if (!found) 2.51 - throw new AssertionError("Missing symbol in where clause " + type); 2.52 - return index + 1; 2.53 - } 2.54 - 2.55 - private boolean unique(TypeVar typevar) { 2.56 - int found = 0; 2.57 - for (Type t : whereClauses.get(WhereClauseKind.TYPEVAR).keySet()) { 2.58 - if (t.toString().equals(typevar.toString())) { 2.59 - found++; 2.60 - } 2.61 - } 2.62 - if (found < 1) 2.63 - throw new AssertionError("Missing type variable in where clause " + typevar); 2.64 - return found == 1; 2.65 - } 2.66 - 2.67 @Override 2.68 protected String printMethodArgs(List<Type> args, boolean varArgs, Locale locale) { 2.69 return super.printMethodArgs(args, varArgs, locale); 2.70 @@ -492,7 +491,7 @@ 2.71 2.72 @Override 2.73 public Void visitCapturedType(CapturedType t, Void ignored) { 2.74 - if (!whereClauses.get(WhereClauseKind.CAPTURED).containsKey(t)) { 2.75 + if (indexOf(t, WhereClauseKind.CAPTURED) == -1) { 2.76 String suffix = t.lower == syms.botType ? ".1" : ""; 2.77 JCDiagnostic d = diags.fragment("where.captured"+ suffix, t, t.bound, t.lower, t.wildcard); 2.78 whereClauses.get(WhereClauseKind.CAPTURED).put(t, d); 2.79 @@ -506,7 +505,7 @@ 2.80 @Override 2.81 public Void visitClassType(ClassType t, Void ignored) { 2.82 if (t.isCompound()) { 2.83 - if (!whereClauses.get(WhereClauseKind.INTERSECTION).containsKey(t)) { 2.84 + if (indexOf(t, WhereClauseKind.INTERSECTION) == -1) { 2.85 Type supertype = types.supertype(t); 2.86 List<Type> interfaces = types.interfaces(t); 2.87 JCDiagnostic d = diags.fragment("where.intersection", t, interfaces.prepend(supertype)); 2.88 @@ -524,7 +523,7 @@ 2.89 2.90 @Override 2.91 public Void visitTypeVar(TypeVar t, Void ignored) { 2.92 - if (!whereClauses.get(WhereClauseKind.TYPEVAR).containsKey(t)) { 2.93 + if (indexOf(t, WhereClauseKind.TYPEVAR) == -1) { 2.94 Type bound = t.bound; 2.95 while ((bound instanceof ErrorType)) 2.96 bound = ((ErrorType)bound).getOriginalType();
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/Diagnostics/6862608/T6862608a.java Thu Jul 30 10:30:10 2009 +0100 3.3 @@ -0,0 +1,44 @@ 3.4 +/* 3.5 + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 3.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 3.24 + * have any questions. 3.25 + */ 3.26 + 3.27 +/** 3.28 + * @test 3.29 + * @bug 6862608 3.30 + * @summary rich diagnostic sometimes contain wrong type variable numbering 3.31 + * @author mcimadamore 3.32 + * @compile/fail/ref=T6862608a.out -XDrawDiagnostics -XDdiags=disambiguateTvars,where T6862608a.java 3.33 + */ 3.34 + 3.35 + 3.36 +import java.util.*; 3.37 + 3.38 +class T6862608a { 3.39 + 3.40 + <T> Comparator<T> compound(Iterable<? extends Comparator<? super T>> it) { 3.41 + return null; 3.42 + } 3.43 + 3.44 + public void test(List<Comparator<?>> x) { 3.45 + Comparator<String> c3 = compound(x); 3.46 + } 3.47 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/Diagnostics/6862608/T6862608a.out Thu Jul 30 10:30:10 2009 +0100 4.3 @@ -0,0 +1,3 @@ 4.4 +T6862608a.java:42:41: compiler.err.invalid.inferred.types: T, (compiler.misc.inferred.do.not.conform.to.params: java.lang.Iterable<? extends java.util.Comparator<? super java.lang.String>>, java.util.List<java.util.Comparator<?>>) 4.5 +- compiler.misc.where.description.typevar: T,{(compiler.misc.where.typevar: T, java.lang.Object, kindname.method, <T>compound(java.lang.Iterable<? extends java.util.Comparator<? super T>>))} 4.6 +1 error
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/tools/javac/Diagnostics/6862608/T6862608b.java Thu Jul 30 10:30:10 2009 +0100 5.3 @@ -0,0 +1,38 @@ 5.4 +/* 5.5 + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 5.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 5.24 + * have any questions. 5.25 + */ 5.26 + 5.27 +/** 5.28 + * @test 5.29 + * @bug 6862608 5.30 + * @summary rich diagnostic sometimes contain wrong type variable numbering 5.31 + * @author mcimadamore 5.32 + * @compile/fail/ref=T6862608b.out -XDrawDiagnostics -XDdiags=disambiguateTvars,where T6862608b.java 5.33 + */ 5.34 + 5.35 +class T66862608b<T extends String, S> { 5.36 + <S, T extends S> void foo(T t) { 5.37 + test(t); 5.38 + } 5.39 + 5.40 + void test(T t) {} 5.41 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/tools/javac/Diagnostics/6862608/T6862608b.out Thu Jul 30 10:30:10 2009 +0100 6.3 @@ -0,0 +1,3 @@ 6.4 +T6862608b.java:34:7: compiler.err.cant.apply.symbol: kindname.method, test, compiler.misc.type.var: T, 1, compiler.misc.type.var: T, 2, kindname.class, T66862608b<compiler.misc.type.var: T, 1,compiler.misc.type.var: S, 2>, null 6.5 +- compiler.misc.where.description.typevar.1: compiler.misc.type.var: T, 1,compiler.misc.type.var: T, 2,compiler.misc.type.var: S, 1,compiler.misc.type.var: S, 2,{(compiler.misc.where.typevar: compiler.misc.type.var: T, 1, java.lang.String, kindname.class, T66862608b),(compiler.misc.where.typevar: compiler.misc.type.var: T, 2, compiler.misc.type.var: S, 1, kindname.method, <compiler.misc.type.var: S, 1,compiler.misc.type.var: T, 2>foo(compiler.misc.type.var: T, 2)),(compiler.misc.where.typevar: compiler.misc.type.var: S, 1, java.lang.Object, kindname.method, <compiler.misc.type.var: S, 1,compiler.misc.type.var: T, 2>foo(compiler.misc.type.var: T, 2)),(compiler.misc.where.typevar: compiler.misc.type.var: S, 2, java.lang.Object, kindname.class, T66862608b)} 6.6 +1 error