Skip to content

Commit f9c8e19

Browse files
committed
Merge branch 'master' into new-destructure
2 parents 5571cec + 2b4d741 commit f9c8e19

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/main/clojure/cljs/analyzer.cljc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,13 +2510,14 @@ x (not (contains? ret :info)))
25102510
(loop [bes []
25112511
env (assoc encl-env :context :expr)
25122512
bindings (seq (partition 2 bindings))]
2513-
25142513
(if-some [[name init] (first bindings)]
2515-
(let []
2514+
(do
25162515
(when (or (some? (namespace name))
25172516
#?(:clj (.contains (str name) ".")
25182517
:cljs ^boolean (goog.string/contains (str name) ".")))
25192518
(throw (error encl-env (str "Invalid local name: " name))))
2519+
(when (= '& name)
2520+
(throw (error encl-env "Can't use & as a local binding")))
25202521
(let [init-expr (analyze-let-binding-init env init (cons {:params bes} *loop-lets*))
25212522
line (get-line name env)
25222523
col (get-col name env)

src/test/clojure/cljs/compiler_tests.clj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,30 @@
401401
(if (gobject/containsKey nil nil) true false)]))]
402402
(is (nil? (re-find #"truth_" code))))))
403403

404+
(deftest test-amp-as-local-clj-2954
405+
(testing "& disallowed as local binding"
406+
(try
407+
(env/with-compiler-env (env/default-compiler-env)
408+
(compile-form-seq
409+
'[(let [& 42] &)]))
410+
(catch Throwable t
411+
(is (instance? clojure.lang.ExceptionInfo t))
412+
(is (.startsWith (-> t ex-cause ex-message) "Can't use & as a local binding"))))
413+
(try
414+
(env/with-compiler-env (env/default-compiler-env)
415+
(compile-form-seq
416+
'[(let* [& 42] &)]))
417+
(catch Throwable t
418+
(is (instance? clojure.lang.ExceptionInfo t))
419+
(is (.startsWith (-> t ex-cause ex-message) "Can't use & as a local binding"))))
420+
(try
421+
(env/with-compiler-env (env/default-compiler-env)
422+
(compile-form-seq
423+
'[(loop* [& 42] &)]))
424+
(catch Throwable t
425+
(is (instance? clojure.lang.ExceptionInfo t))
426+
(is (.startsWith (-> t ex-cause ex-message) "Can't use & as a local binding"))))))
427+
404428
;; CLJS-1225
405429

406430
(comment

0 commit comments

Comments
 (0)