8020286: Wrong diagnostic after compaction

Wed, 17 Jul 2013 14:14:32 +0100

author
mcimadamore
date
Wed, 17 Jul 2013 14:14:32 +0100
changeset 1900
328896931b98
parent 1899
c60a5099863a
child 1901
db2c539819dd

8020286: Wrong diagnostic after compaction
Summary: compact diagnostic shows the least relevant method in the list
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/comp/Resolve.java file | annotate | diff | comparison | revisions
test/tools/javac/Diagnostics/compressed/T8020286.java file | annotate | diff | comparison | revisions
test/tools/javac/Diagnostics/compressed/T8020286.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Wed Jul 17 14:13:15 2013 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Wed Jul 17 14:14:32 2013 +0100
     1.3 @@ -2490,7 +2490,7 @@
     1.4                      Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
     1.5                          if (sym.kind >= AMBIGUOUS) {
     1.6                              final JCDiagnostic details = sym.kind == WRONG_MTH ?
     1.7 -                                            ((InapplicableSymbolError)sym).errCandidate().details :
     1.8 +                                            ((InapplicableSymbolError)sym).errCandidate().snd :
     1.9                                              null;
    1.10                              sym = new InapplicableSymbolError(sym.kind, "diamondError", currentResolutionContext) {
    1.11                                  @Override
    1.12 @@ -3442,20 +3442,20 @@
    1.13                          key, name, first, second);
    1.14              }
    1.15              else {
    1.16 -                Candidate c = errCandidate();
    1.17 +                Pair<Symbol, JCDiagnostic> c = errCandidate();
    1.18                  if (compactMethodDiags) {
    1.19                      for (Map.Entry<Template, DiagnosticRewriter> _entry :
    1.20                              MethodResolutionDiagHelper.rewriters.entrySet()) {
    1.21 -                        if (_entry.getKey().matches(c.details)) {
    1.22 +                        if (_entry.getKey().matches(c.snd)) {
    1.23                              JCDiagnostic simpleDiag =
    1.24                                      _entry.getValue().rewriteDiagnostic(diags, pos,
    1.25 -                                        log.currentSource(), dkind, c.details);
    1.26 +                                        log.currentSource(), dkind, c.snd);
    1.27                              simpleDiag.setFlag(DiagnosticFlag.COMPRESSED);
    1.28                              return simpleDiag;
    1.29                          }
    1.30                      }
    1.31                  }
    1.32 -                Symbol ws = c.sym.asMemberOf(site, types);
    1.33 +                Symbol ws = c.fst.asMemberOf(site, types);
    1.34                  return diags.create(dkind, log.currentSource(), pos,
    1.35                            "cant.apply.symbol",
    1.36                            kindName(ws),
    1.37 @@ -3464,7 +3464,7 @@
    1.38                            methodArguments(argtypes),
    1.39                            kindName(ws.owner),
    1.40                            ws.owner.type,
    1.41 -                          c.details);
    1.42 +                          c.snd);
    1.43              }
    1.44          }
    1.45  
    1.46 @@ -3473,14 +3473,14 @@
    1.47              return types.createErrorType(name, location, syms.errSymbol.type).tsym;
    1.48          }
    1.49  
    1.50 -        private Candidate errCandidate() {
    1.51 +        protected Pair<Symbol, JCDiagnostic> errCandidate() {
    1.52              Candidate bestSoFar = null;
    1.53              for (Candidate c : resolveContext.candidates) {
    1.54                  if (c.isApplicable()) continue;
    1.55                  bestSoFar = c;
    1.56              }
    1.57              Assert.checkNonNull(bestSoFar);
    1.58 -            return bestSoFar;
    1.59 +            return new Pair<Symbol, JCDiagnostic>(bestSoFar.sym, bestSoFar.details);
    1.60          }
    1.61      }
    1.62  
    1.63 @@ -3523,7 +3523,15 @@
    1.64                          methodArguments(argtypes));
    1.65                  return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(filteredCandidates, site));
    1.66              } else if (filteredCandidates.size() == 1) {
    1.67 -                JCDiagnostic d =  new InapplicableSymbolError(resolveContext).getDiagnostic(dkind, pos,
    1.68 +                Map.Entry<Symbol, JCDiagnostic> _e =
    1.69 +                                filteredCandidates.entrySet().iterator().next();
    1.70 +                final Pair<Symbol, JCDiagnostic> p = new Pair<Symbol, JCDiagnostic>(_e.getKey(), _e.getValue());
    1.71 +                JCDiagnostic d = new InapplicableSymbolError(resolveContext) {
    1.72 +                    @Override
    1.73 +                    protected Pair<Symbol, JCDiagnostic> errCandidate() {
    1.74 +                        return p;
    1.75 +                    }
    1.76 +                }.getDiagnostic(dkind, pos,
    1.77                      location, site, name, argtypes, typeargtypes);
    1.78                  if (truncatedDiag) {
    1.79                      d.setFlag(DiagnosticFlag.COMPRESSED);
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/Diagnostics/compressed/T8020286.java	Wed Jul 17 14:14:32 2013 +0100
     2.3 @@ -0,0 +1,15 @@
     2.4 +/**
     2.5 + * @test /nodynamiccopyright/
     2.6 + * @bug     8020286
     2.7 + * @summary Wrong diagnostic after compaction
     2.8 + * @compile/fail/ref=T8020286.out -XDrawDiagnostics -Xdiags:compact T8020286.java
     2.9 + */
    2.10 +
    2.11 +class T8020286 {
    2.12 +   void m(String s) { }
    2.13 +   void m(Integer i, String s) { }
    2.14 +   void test() {
    2.15 +       m(1, 1);
    2.16 +       m(1);
    2.17 +   }
    2.18 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/Diagnostics/compressed/T8020286.out	Wed Jul 17 14:14:32 2013 +0100
     3.3 @@ -0,0 +1,4 @@
     3.4 +T8020286.java:12:13: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.String)
     3.5 +T8020286.java:13:10: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.String)
     3.6 +- compiler.note.compressed.diags
     3.7 +2 errors

mercurial