changeset 2237:f75d9c517541

8020286: Wrong diagnostic after compaction
author mcimadamore
date Wed, 10 Jul 2013 18:01:53 +0100
parents 1f469f8884c3
children a6e792b06adc
files src/share/classes/com/sun/tools/javac/comp/Resolve.java test/tools/javac/Diagnostics/compressed/T8020286.java test/tools/javac/Diagnostics/compressed/T8020286.out
diffstat 3 files changed, 36 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Wed Jul 10 14:00:50 2013 +0100
+++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Wed Jul 10 18:01:53 2013 +0100
@@ -2497,7 +2497,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
@@ -3427,20 +3427,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),
@@ -3449,7 +3449,7 @@
                           methodArguments(argtypes),
                           kindName(ws.owner),
                           ws.owner.type,
-                          c.details);
+                          c.snd);
             }
         }
 
@@ -3458,14 +3458,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);
         }
     }
 
@@ -3508,7 +3508,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/test/tools/javac/Diagnostics/compressed/T8020286.java	Wed Jul 10 18:01:53 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/test/tools/javac/Diagnostics/compressed/T8020286.out	Wed Jul 10 18:01:53 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