Skip to content

Commit 42c6930

Browse files
committed
CLJS-667: validate extend-type and extend-protocol shape
1 parent 9a1fae9 commit 42c6930

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/clj/cljs/analyzer.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
:protocol-multiple-impls true
7171
:single-segment-namespace true
7272
:munged-namespace true
73-
:ns-var-clash true})
73+
:ns-var-clash true
74+
:extend-type-invalid-method-shape true})
7475

7576
(def js-reserved
7677
#{"abstract" "boolean" "break" "byte" "case"
@@ -214,6 +215,11 @@
214215
[warning-type {:keys [ns var] :as info}]
215216
(str "Namespace " ns " clashes with var " var))
216217

218+
(defmethod error-message :extend-type-invalid-method-shape
219+
[warning-type {:keys [protocol method] :as info}]
220+
(str "Bad extend-type method shape for protocol " protocol " method " method
221+
", method arities must be grouped together"))
222+
217223
(defn ^:private default-warning-handler [warning-type env extra]
218224
(when (warning-type *cljs-warnings*)
219225
(when-let [s (error-message warning-type extra)]

src/clj/cljs/core.clj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,14 @@
875875
impls (drop-while seq? (next impls))]
876876
(when (contains? protos proto)
877877
(ana/warning :protocol-multiple-impls env {:protocol proto}))
878-
(core/doseq [method methods]
879-
(validate-impl-sigs env proto method))
878+
(loop [seen #{} methods methods]
879+
(when (seq methods)
880+
(let [[fname :as method] (first methods)]
881+
(when (contains? seen fname)
882+
(ana/warning :extend-type-invalid-method-shape env
883+
{:protocol proto :method fname}))
884+
(validate-impl-sigs env proto method)
885+
(recur (conj seen fname) (next methods)))))
880886
(recur (conj protos proto) impls)))))
881887

882888
(defmacro extend-type

0 commit comments

Comments
 (0)