提交 c9a360eb 编写于 作者: M mcimadamore

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
上级 bdae2d72
......@@ -1003,7 +1003,7 @@ compiler.misc.inferred.do.not.conform.to.bounds=\
inferred: {0}\n\
bound(s): {1}
compiler.misc.inferred.do.not.conform.to.params=\
actual arguments do not conforms to inferred formal arguments\n\
actual arguments do not conform to inferred formal arguments\n\
required: {0}\n\
found: {1}
......
......@@ -208,6 +208,32 @@ public class RichDiagnosticFormatter extends
}
return clauses.reverse();
}
private int indexOf(Type type, WhereClauseKind kind) {
int index = 1;
for (Type t : whereClauses.get(kind).keySet()) {
if (t.tsym == type.tsym) {
return index;
}
if (kind != WhereClauseKind.TYPEVAR ||
t.toString().equals(type.toString())) {
index++;
}
}
return -1;
}
private boolean unique(TypeVar typevar) {
int found = 0;
for (Type t : whereClauses.get(WhereClauseKind.TYPEVAR).keySet()) {
if (t.toString().equals(typevar.toString())) {
found++;
}
}
if (found < 1)
throw new AssertionError("Missing type variable in where clause " + typevar);
return found == 1;
}
//where
/**
* This enum defines all posssible kinds of where clauses that can be
......@@ -366,33 +392,6 @@ public class RichDiagnosticFormatter extends
}
}
private int indexOf(Type type, WhereClauseKind kind) {
int index = 0;
boolean found = false;
for (Type t : whereClauses.get(kind).keySet()) {
if (t == type) {
found = true;
break;
}
index++;
}
if (!found)
throw new AssertionError("Missing symbol in where clause " + type);
return index + 1;
}
private boolean unique(TypeVar typevar) {
int found = 0;
for (Type t : whereClauses.get(WhereClauseKind.TYPEVAR).keySet()) {
if (t.toString().equals(typevar.toString())) {
found++;
}
}
if (found < 1)
throw new AssertionError("Missing type variable in where clause " + typevar);
return found == 1;
}
@Override
protected String printMethodArgs(List<Type> args, boolean varArgs, Locale locale) {
return super.printMethodArgs(args, varArgs, locale);
......@@ -492,7 +491,7 @@ public class RichDiagnosticFormatter extends
@Override
public Void visitCapturedType(CapturedType t, Void ignored) {
if (!whereClauses.get(WhereClauseKind.CAPTURED).containsKey(t)) {
if (indexOf(t, WhereClauseKind.CAPTURED) == -1) {
String suffix = t.lower == syms.botType ? ".1" : "";
JCDiagnostic d = diags.fragment("where.captured"+ suffix, t, t.bound, t.lower, t.wildcard);
whereClauses.get(WhereClauseKind.CAPTURED).put(t, d);
......@@ -506,7 +505,7 @@ public class RichDiagnosticFormatter extends
@Override
public Void visitClassType(ClassType t, Void ignored) {
if (t.isCompound()) {
if (!whereClauses.get(WhereClauseKind.INTERSECTION).containsKey(t)) {
if (indexOf(t, WhereClauseKind.INTERSECTION) == -1) {
Type supertype = types.supertype(t);
List<Type> interfaces = types.interfaces(t);
JCDiagnostic d = diags.fragment("where.intersection", t, interfaces.prepend(supertype));
......@@ -524,7 +523,7 @@ public class RichDiagnosticFormatter extends
@Override
public Void visitTypeVar(TypeVar t, Void ignored) {
if (!whereClauses.get(WhereClauseKind.TYPEVAR).containsKey(t)) {
if (indexOf(t, WhereClauseKind.TYPEVAR) == -1) {
Type bound = t.bound;
while ((bound instanceof ErrorType))
bound = ((ErrorType)bound).getOriginalType();
......
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @test
* @bug 6862608
* @summary rich diagnostic sometimes contain wrong type variable numbering
* @author mcimadamore
* @compile/fail/ref=T6862608a.out -XDrawDiagnostics -XDdiags=disambiguateTvars,where T6862608a.java
*/
import java.util.*;
class T6862608a {
<T> Comparator<T> compound(Iterable<? extends Comparator<? super T>> it) {
return null;
}
public void test(List<Comparator<?>> x) {
Comparator<String> c3 = compound(x);
}
}
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<?>>)
- 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>>))}
1 error
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @test
* @bug 6862608
* @summary rich diagnostic sometimes contain wrong type variable numbering
* @author mcimadamore
* @compile/fail/ref=T6862608b.out -XDrawDiagnostics -XDdiags=disambiguateTvars,where T6862608b.java
*/
class T66862608b<T extends String, S> {
<S, T extends S> void foo(T t) {
test(t);
}
void test(T t) {}
}
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
- 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)}
1 error
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册