Skip to content

Commit ea51c78

Browse files
committed
Fix #997: Var is mistaken for local when used under the same name in a let body
1 parent 2c00616 commit ea51c78

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/sci/impl/analyzer.cljc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,11 +1234,10 @@
12341234

12351235
;;;; Vars
12361236

1237-
(defn analyze-var [ctx [_ var-name]]
1238-
(second
1239-
(resolve/lookup (assoc ctx :bindings {}) var-name false nil true)))
1240-
1241-
#_(sci.core/eval-string "(def x 2) (let [x 1 x #'x] x)")
1237+
(defn analyze-var [ctx [_ var-name :as expr]]
1238+
(or (second
1239+
(resolve/lookup (assoc ctx :bindings {}) var-name false nil true))
1240+
(throw-error-with-location (str "Unable to resolve var: " var-name) expr)))
12421241

12431242
(defn analyze-set! [ctx [_ obj v :as expr]]
12441243
(cond

test/sci/core_test.cljc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,8 @@
342342
:cljs (is (nil? (sci/eval-string "(resolve 'js/Error)" {:classes {'js #js {:Error js/Error}}}))))
343343
(is (= 1 (eval* "((binding [*ns* 'user] (resolve 'inc)) 0)")))
344344
(is (= 2 (eval* "(def x 2) (let [x 1 x #'x] @x)")))
345-
;; TODO: crash: user=> (sci/eval-string "#'ffoooo")
346-
nil
347-
)
345+
(is (thrown-with-msg? Exception #"dude" (eval* "(defn foo [] #'dude)")))
346+
(is (thrown-with-msg? Exception #"inc" (sci/eval-string "(defn foo [] #'inc)" {:deny '[inc]}))))
348347

349348
#?(:clj
350349
(deftest type-hint-let-test

0 commit comments

Comments
 (0)