Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/clojure/cljs/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2510,13 +2510,14 @@ x (not (contains? ret :info)))
(loop [bes []
env (assoc encl-env :context :expr)
bindings (seq (partition 2 bindings))]

(if-some [[name init] (first bindings)]
(let []
(do
(when (or (some? (namespace name))
#?(:clj (.contains (str name) ".")
:cljs ^boolean (goog.string/contains (str name) ".")))
(throw (error encl-env (str "Invalid local name: " name))))
(when (= '& name)
(throw (error encl-env "Can't use & as a local binding")))
(let [init-expr (analyze-let-binding-init env init (cons {:params bes} *loop-lets*))
line (get-line name env)
col (get-col name env)
Expand Down
24 changes: 24 additions & 0 deletions src/test/clojure/cljs/compiler_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,30 @@
(if (gobject/containsKey nil nil) true false)]))]
(is (nil? (re-find #"truth_" code))))))

(deftest test-amp-as-local-clj-2954
(testing "& disallowed as local binding"
(try
(env/with-compiler-env (env/default-compiler-env)
(compile-form-seq
'[(let [& 42] &)]))
(catch Throwable t
(is (instance? clojure.lang.ExceptionInfo t))
(is (.startsWith (-> t ex-cause ex-message) "Can't use & as a local binding"))))
(try
(env/with-compiler-env (env/default-compiler-env)
(compile-form-seq
'[(let* [& 42] &)]))
(catch Throwable t
(is (instance? clojure.lang.ExceptionInfo t))
(is (.startsWith (-> t ex-cause ex-message) "Can't use & as a local binding"))))
(try
(env/with-compiler-env (env/default-compiler-env)
(compile-form-seq
'[(loop* [& 42] &)]))
(catch Throwable t
(is (instance? clojure.lang.ExceptionInfo t))
(is (.startsWith (-> t ex-cause ex-message) "Can't use & as a local binding"))))))

;; CLJS-1225

(comment
Expand Down
Loading