changeset 47363:9bfa788c53ee patterns

manual merge
author mcimadamore
date Mon, 02 Oct 2017 18:25:30 +0100
parents 4e65cd35d23e 2e947e1bd907
children 798ec6ef8ab3
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java test/langtools/tools/javac/capture/Martin.out test/langtools/tools/javac/lambda/8019480/T8019480.out
diffstat 3 files changed, 26 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Mon Oct 02 18:40:38 2017 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Mon Oct 02 18:25:30 2017 +0100
@@ -59,6 +59,7 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
+import java.util.LinkedList;
 import java.util.Map;
 import java.util.Set;
 import java.util.function.BiFunction;
@@ -4040,14 +4041,35 @@
         }
         //where
             private Map<Symbol, JCDiagnostic> mapCandidates() {
-                Map<Symbol, JCDiagnostic> candidates = new LinkedHashMap<>();
+                MostSpecificMap candidates = new MostSpecificMap();
                 for (Candidate c : resolveContext.candidates) {
                     if (c.isApplicable()) continue;
-                    candidates.put(c.sym, c.details);
+                    candidates.put(c);
                 }
                 return candidates;
             }
 
+            @SuppressWarnings("serial")
+            private class MostSpecificMap extends LinkedHashMap<Symbol, JCDiagnostic> {
+                private void put(Candidate c) {
+                    ListBuffer<Symbol> overridden = new ListBuffer<>();
+                    for (Symbol s : keySet()) {
+                        if (s == c.sym) {
+                            continue;
+                        }
+                        if (c.sym.overrides(s, (TypeSymbol)s.owner, types, false)) {
+                            overridden.add(s);
+                        } else if (s.overrides(c.sym, (TypeSymbol)c.sym.owner, types, false)) {
+                            return;
+                        }
+                    }
+                    for (Symbol s : overridden) {
+                        remove(s);
+                    }
+                    put(c.sym, c.details);
+                }
+            }
+
             Map<Symbol, JCDiagnostic> filterCandidates(Map<Symbol, JCDiagnostic> candidatesMap) {
                 Map<Symbol, JCDiagnostic> candidates = new LinkedHashMap<>();
                 for (Map.Entry<Symbol, JCDiagnostic> _entry : candidatesMap.entrySet()) {
--- a/test/langtools/tools/javac/capture/Martin.out	Mon Oct 02 18:40:38 2017 +0200
+++ b/test/langtools/tools/javac/capture/Martin.out	Mon Oct 02 18:25:30 2017 +0100
@@ -1,2 +1,2 @@
-Martin.java:15:11: compiler.err.cant.apply.symbols: kindname.method, addAll, java.util.List<compiler.misc.type.captureof: 1, ?>,{(compiler.misc.inapplicable.method: kindname.method, java.util.Collection, addAll(java.util.Collection<? extends compiler.misc.type.captureof: 2, ?>), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.Collection<? extends compiler.misc.type.captureof: 2, ?>))),(compiler.misc.inapplicable.method: kindname.method, java.util.List, addAll(java.util.Collection<? extends compiler.misc.type.captureof: 2, ?>), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.Collection<? extends compiler.misc.type.captureof: 2, ?>))),(compiler.misc.inapplicable.method: kindname.method, java.util.List, addAll(int,java.util.Collection<? extends compiler.misc.type.captureof: 2, ?>), (compiler.misc.arg.length.mismatch))}
+Martin.java:15:11: compiler.err.cant.apply.symbols: kindname.method, addAll, java.util.List<compiler.misc.type.captureof: 1, ?>,{(compiler.misc.inapplicable.method: kindname.method, java.util.List, addAll(java.util.Collection<? extends compiler.misc.type.captureof: 2, ?>), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.Collection<? extends compiler.misc.type.captureof: 2, ?>))),(compiler.misc.inapplicable.method: kindname.method, java.util.List, addAll(int,java.util.Collection<? extends compiler.misc.type.captureof: 2, ?>), (compiler.misc.arg.length.mismatch))}
 1 error
--- a/test/langtools/tools/javac/lambda/8019480/T8019480.out	Mon Oct 02 18:40:38 2017 +0200
+++ b/test/langtools/tools/javac/lambda/8019480/T8019480.out	Mon Oct 02 18:25:30 2017 +0100
@@ -1,3 +1,3 @@
-T8019480.java:21:34: compiler.err.cant.apply.symbols: kindname.method, add, java.lang.Object,{(compiler.misc.inapplicable.method: kindname.method, java.util.Collection, add(U), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.Object, U))),(compiler.misc.inapplicable.method: kindname.method, java.util.List, add(U), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.Object, U))),(compiler.misc.inapplicable.method: kindname.method, java.util.List, add(int,U), (compiler.misc.arg.length.mismatch))}
+T8019480.java:21:34: compiler.err.cant.apply.symbols: kindname.method, add, java.lang.Object,{(compiler.misc.inapplicable.method: kindname.method, java.util.List, add(U), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.Object, U))),(compiler.misc.inapplicable.method: kindname.method, java.util.List, add(int,U), (compiler.misc.arg.length.mismatch))}
 T8019480.java:21:46: compiler.err.report.access: clone(), protected, java.lang.Object
 2 errors