mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-17 03:13:11 +00:00
6758789: Some method resolution diagnostic should be improved
Recent work on diagnostics left out some resolution corner cases Reviewed-by: jjg
This commit is contained in:
parent
dd2a864f51
commit
418461fae2
@ -49,4 +49,23 @@ public interface Formattable {
|
||||
* @return a string representing the object's kind
|
||||
*/
|
||||
String getKind();
|
||||
|
||||
static class LocalizedString implements Formattable {
|
||||
String key;
|
||||
|
||||
public LocalizedString(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String toString(java.util.Locale l, Messages messages) {
|
||||
return messages.getLocalizedString(l, key);
|
||||
}
|
||||
public String getKind() {
|
||||
return "LocalizedString";
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2378,16 +2378,14 @@ public class Attr extends JCTree.Visitor {
|
||||
}
|
||||
|
||||
if (warned && sym.type.tag == FORALL) {
|
||||
String typeargs = "";
|
||||
if (typeargtypes != null && typeargtypes.nonEmpty()) {
|
||||
typeargs = "<" + Type.toString(typeargtypes) + ">";
|
||||
}
|
||||
chk.warnUnchecked(env.tree.pos(),
|
||||
"unchecked.meth.invocation.applied",
|
||||
sym,
|
||||
sym.location(),
|
||||
typeargs,
|
||||
Type.toString(argtypes));
|
||||
kindName(sym),
|
||||
sym.name,
|
||||
rs.methodArguments(sym.type.getParameterTypes()),
|
||||
rs.methodArguments(argtypes),
|
||||
kindName(sym.location()),
|
||||
sym.location());
|
||||
owntype = new MethodType(owntype.getParameterTypes(),
|
||||
types.erasure(owntype.getReturnType()),
|
||||
owntype.getThrownTypes(),
|
||||
|
||||
@ -30,6 +30,7 @@ import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
|
||||
import com.sun.tools.javac.code.*;
|
||||
import com.sun.tools.javac.jvm.*;
|
||||
import com.sun.tools.javac.tree.*;
|
||||
import com.sun.tools.javac.api.Formattable.LocalizedString;
|
||||
import static com.sun.tools.javac.comp.Resolve.MethodResolutionPhase.*;
|
||||
|
||||
import com.sun.tools.javac.code.Type.*;
|
||||
@ -1478,6 +1479,12 @@ public class Resolve {
|
||||
error.report(log, tree.pos(), type.getEnclosingType(), null, null, null);
|
||||
}
|
||||
|
||||
private final LocalizedString noArgs = new LocalizedString("compiler.misc.no.args");
|
||||
|
||||
public Object methodArguments(List<Type> argtypes) {
|
||||
return argtypes.isEmpty() ? noArgs : argtypes;
|
||||
}
|
||||
|
||||
/** Root class for resolve errors.
|
||||
* Instances of this class indicate "Symbol not found".
|
||||
* Instances of subclass indicate other errors.
|
||||
@ -1584,8 +1591,8 @@ public class Resolve {
|
||||
"cant.apply.symbol" + (explanation != null ? ".1" : ""),
|
||||
kindname,
|
||||
ws.name == names.init ? ws.owner.name : ws.name,
|
||||
ws.type.getParameterTypes(),
|
||||
argtypes,
|
||||
methodArguments(ws.type.getParameterTypes()),
|
||||
methodArguments(argtypes),
|
||||
kindName(ws.owner),
|
||||
ws.owner.type,
|
||||
explanation);
|
||||
|
||||
@ -745,7 +745,10 @@ compiler.warn.unchecked.call.mbr.of.raw.type=\
|
||||
compiler.warn.unchecked.cast.to.type=\
|
||||
[unchecked] unchecked cast to type {0}
|
||||
compiler.warn.unchecked.meth.invocation.applied=\
|
||||
[unchecked] unchecked method invocation: {0} in {1} is applied to {2}({3})
|
||||
[unchecked] unchecked method invocation: {0} {1} in {4} {5} is applied to given types\n\
|
||||
required: {2}\n\
|
||||
found: {3}
|
||||
|
||||
compiler.warn.unchecked.generic.array.creation=\
|
||||
[unchecked] unchecked generic array creation of type {0} for varargs parameter
|
||||
|
||||
@ -1062,6 +1065,9 @@ compiler.misc.kindname.package=\
|
||||
package
|
||||
#####
|
||||
|
||||
compiler.misc.no.args=\
|
||||
no arguments
|
||||
|
||||
compiler.err.override.static=\
|
||||
{0}; overriding method is static
|
||||
compiler.err.override.meth=\
|
||||
|
||||
40
langtools/test/tools/javac/6758789/T6758789a.java
Normal file
40
langtools/test/tools/javac/6758789/T6758789a.java
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2008 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 6758789
|
||||
* @summary 6758789: Some method resolution diagnostic should be improved
|
||||
* @author Maurizio Cimadamore
|
||||
*
|
||||
* @compile/fail/ref=T6758789a.out -XDrawDiagnostics T6758789a.java
|
||||
*/
|
||||
|
||||
class T6758789a {
|
||||
void m1() {}
|
||||
void m2(int i) {}
|
||||
void test() {
|
||||
m1(1);
|
||||
m2();
|
||||
}
|
||||
}
|
||||
3
langtools/test/tools/javac/6758789/T6758789a.out
Normal file
3
langtools/test/tools/javac/6758789/T6758789a.out
Normal file
@ -0,0 +1,3 @@
|
||||
T6758789a.java:37:9: compiler.err.cant.apply.symbol: kindname.method, m1, compiler.misc.no.args, int, kindname.class, T6758789a, null
|
||||
T6758789a.java:38:9: compiler.err.cant.apply.symbol: kindname.method, m2, int, compiler.misc.no.args, kindname.class, T6758789a, null
|
||||
2 errors
|
||||
41
langtools/test/tools/javac/6758789/T6758789b.java
Normal file
41
langtools/test/tools/javac/6758789/T6758789b.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2008 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 6758789
|
||||
* @summary 6758789: Some method resolution diagnostic should be improved
|
||||
* @author Maurizio Cimadamore
|
||||
*
|
||||
* @compile/fail/ref=T6758789b.out -Werror -XDrawDiagnostics -Xlint:unchecked T6758789b.java
|
||||
*/
|
||||
|
||||
class T6758789a {
|
||||
class Foo<T> {}
|
||||
|
||||
<X> void m(Foo<X> foo) {}
|
||||
|
||||
void test() {
|
||||
m(new Foo());
|
||||
}
|
||||
}
|
||||
3
langtools/test/tools/javac/6758789/T6758789b.out
Normal file
3
langtools/test/tools/javac/6758789/T6758789b.out
Normal file
@ -0,0 +1,3 @@
|
||||
T6758789b.java:39:11: compiler.warn.prob.found.req: (- compiler.misc.unchecked.assign), T6758789a.Foo, T6758789a.Foo<X>
|
||||
T6758789b.java:39:10: compiler.warn.unchecked.meth.invocation.applied: kindname.method, m, T6758789a.Foo<X>, T6758789a.Foo, kindname.class, T6758789a
|
||||
2 warnings
|
||||
@ -1,3 +1,3 @@
|
||||
T6718364.java:36:32: compiler.warn.prob.found.req: (- compiler.misc.unchecked.assign), T6718364.X, T6718364.X<java.lang.Integer>
|
||||
T6718364.java:36:10: compiler.warn.unchecked.meth.invocation.applied: <T>m(T6718364.X<T>,T), T6718364, , T6718364.X<T6718364.X<java.lang.Integer>>,T6718364.X
|
||||
T6718364.java:36:10: compiler.warn.unchecked.meth.invocation.applied: kindname.method, m, T6718364.X<T>,T, T6718364.X<T6718364.X<java.lang.Integer>>,T6718364.X, kindname.class, T6718364
|
||||
2 warnings
|
||||
Loading…
x
Reference in New Issue
Block a user