Skip to content

Commit 53b6624

Browse files
committed
fix: most-specific one
1 parent 2e1723d commit 53b6624

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

  • src/main/clojure/clojure/tools/analyzer/jvm

src/main/clojure/clojure/tools/analyzer/jvm/utils.clj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,22 @@
409409
(= pc (maybe-class mp))))
410410
(map vector param-classes method-params)))))
411411

412+
(defn- most-specific
413+
[methods]
414+
(map (fn [ms]
415+
(reduce (fn [a b]
416+
(if (.isAssignableFrom ^Class (maybe-class (:declaring-class a))
417+
^Class (maybe-class (:declaring-class b)))
418+
b a))
419+
ms))
420+
(vals (group-by #(mapv maybe-class (:parameter-types %)) methods))))
421+
412422
(defn resolve-hinted-method
413423
"Given a class, method name and param-tags, resolves to the unique matching method.
414424
Returns nil if no match or if ambiguous."
415425
[methods param-tags]
416426
(let [param-classes (tags-to-maybe-classes param-tags)
417-
matching (filter #(signature-matches? param-classes %) methods)]
427+
matching (most-specific (filter #(signature-matches? param-classes %) methods))]
418428
(when (= 1 (count matching))
419429
(first matching))))
420430

0 commit comments

Comments
 (0)