Skip to content

Commit 809f23a

Browse files
committed
CLJS-2133: Invalid variadic IFn implementations now fail
revert self__ hoisting, need to emit self__ ref in variadic delegate
1 parent 3417d46 commit 809f23a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Diff for: src/main/clojure/cljs/compiler.cljc

+4-2
Original file line numberDiff line numberDiff line change
@@ -744,13 +744,13 @@
744744
mname (munge name)
745745
delegate-name (str mname "__delegate")]
746746
(emitln "(function() { ")
747-
(when type
748-
(emitln "var self__ = this;"))
749747
(emits "var " delegate-name " = function (")
750748
(doseq [param params]
751749
(emit param)
752750
(when-not (= param (last params)) (emits ",")))
753751
(emitln "){")
752+
(when type
753+
(emitln "var self__ = this;"))
754754
(when recurs (emitln "while(true){"))
755755
(emits expr)
756756
(when recurs
@@ -762,6 +762,8 @@
762762
(if variadic
763763
(concat (butlast params) ['var_args])
764764
params)) "){")
765+
(when type
766+
(emitln "var self__ = this;"))
765767
(when variadic
766768
(emits "var ")
767769
(emit (last params))

Diff for: src/test/cljs/cljs/core_test.cljs

+10
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,16 @@
13391339
(testing "Syntax quoted dotted symbol without namespace should resolve to itself"
13401340
(is (= 'clojure.core `clojure.core))))
13411341

1342+
(deftype Partial [f args]
1343+
IFn
1344+
(-invoke [_ & a]
1345+
(apply (apply partial f args) a)))
1346+
1347+
(deftest test-cljs-2133
1348+
(testing "Invalid variadic IFn implementation should work"
1349+
(let [p (Partial. + [1])]
1350+
(p 2))))
1351+
13421352
(comment
13431353
;; ObjMap
13441354
;; (let [ks (map (partial str "foo") (range 500))

0 commit comments

Comments
 (0)