8020286: Wrong diagnostic after compaction
Summary: compact diagnostic shows the least relevant method in the list
Reviewed-by: jjg
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed Jul 17 14:13:15 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed Jul 17 14:14:32 2013 +0100
@@ -2490,7 +2490,7 @@
Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
if (sym.kind >= AMBIGUOUS) {
final JCDiagnostic details = sym.kind == WRONG_MTH ?
- ((InapplicableSymbolError)sym).errCandidate().details :
+ ((InapplicableSymbolError)sym).errCandidate().snd :
null;
sym = new InapplicableSymbolError(sym.kind, "diamondError", currentResolutionContext) {
@Override
@@ -3442,20 +3442,20 @@
key, name, first, second);
}
else {
- Candidate c = errCandidate();
+ Pair<Symbol, JCDiagnostic> c = errCandidate();
if (compactMethodDiags) {
for (Map.Entry<Template, DiagnosticRewriter> _entry :
MethodResolutionDiagHelper.rewriters.entrySet()) {
- if (_entry.getKey().matches(c.details)) {
+ if (_entry.getKey().matches(c.snd)) {
JCDiagnostic simpleDiag =
_entry.getValue().rewriteDiagnostic(diags, pos,
- log.currentSource(), dkind, c.details);
+ log.currentSource(), dkind, c.snd);
simpleDiag.setFlag(DiagnosticFlag.COMPRESSED);
return simpleDiag;
}
}
}
- Symbol ws = c.sym.asMemberOf(site, types);
+ Symbol ws = c.fst.asMemberOf(site, types);
return diags.create(dkind, log.currentSource(), pos,
"cant.apply.symbol",
kindName(ws),
@@ -3464,7 +3464,7 @@
methodArguments(argtypes),
kindName(ws.owner),
ws.owner.type,
- c.details);
+ c.snd);
}
}
@@ -3473,14 +3473,14 @@
return types.createErrorType(name, location, syms.errSymbol.type).tsym;
}
- private Candidate errCandidate() {
+ protected Pair<Symbol, JCDiagnostic> errCandidate() {
Candidate bestSoFar = null;
for (Candidate c : resolveContext.candidates) {
if (c.isApplicable()) continue;
bestSoFar = c;
}
Assert.checkNonNull(bestSoFar);
- return bestSoFar;
+ return new Pair<Symbol, JCDiagnostic>(bestSoFar.sym, bestSoFar.details);
}
}
@@ -3523,7 +3523,15 @@
methodArguments(argtypes));
return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(filteredCandidates, site));
} else if (filteredCandidates.size() == 1) {
- JCDiagnostic d = new InapplicableSymbolError(resolveContext).getDiagnostic(dkind, pos,
+ Map.Entry<Symbol, JCDiagnostic> _e =
+ filteredCandidates.entrySet().iterator().next();
+ final Pair<Symbol, JCDiagnostic> p = new Pair<Symbol, JCDiagnostic>(_e.getKey(), _e.getValue());
+ JCDiagnostic d = new InapplicableSymbolError(resolveContext) {
+ @Override
+ protected Pair<Symbol, JCDiagnostic> errCandidate() {
+ return p;
+ }
+ }.getDiagnostic(dkind, pos,
location, site, name, argtypes, typeargtypes);
if (truncatedDiag) {
d.setFlag(DiagnosticFlag.COMPRESSED);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/Diagnostics/compressed/T8020286.java Wed Jul 17 14:14:32 2013 +0100
@@ -0,0 +1,15 @@
+/**
+ * @test /nodynamiccopyright/
+ * @bug 8020286
+ * @summary Wrong diagnostic after compaction
+ * @compile/fail/ref=T8020286.out -XDrawDiagnostics -Xdiags:compact T8020286.java
+ */
+
+class T8020286 {
+ void m(String s) { }
+ void m(Integer i, String s) { }
+ void test() {
+ m(1, 1);
+ m(1);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/Diagnostics/compressed/T8020286.out Wed Jul 17 14:14:32 2013 +0100
@@ -0,0 +1,4 @@
+T8020286.java:12:13: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.String)
+T8020286.java:13:10: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.String)
+- compiler.note.compressed.diags
+2 errors