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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ SCI is used in [babashka](https://github.com/babashka/babashka),
[joyride](https://github.com/BetterThanTomorrow/joyride/) and many
[other](https://github.com/babashka/sci#projects-using-sci) projects.

## Unreleased

- Fix [#997](https://github.com/babashka/sci/issues/997): Var is mistaken for local when used under the same name in a `let` body

## 0.10.49 (2025-08-22)

- Fix regression introduced in [#987](https://github.com/babashka/sci/issues/987)
Expand Down
6 changes: 4 additions & 2 deletions src/sci/impl/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1234,8 +1234,10 @@

;;;; Vars

(defn analyze-var [ctx [_ var-name]]
(resolve/resolve-symbol ctx var-name))
(defn analyze-var [ctx [_ var-name :as expr]]
(or (second
(resolve/lookup (assoc ctx :bindings {}) var-name false nil true))
(throw-error-with-location (str "Unable to resolve var: " var-name) expr)))

(defn analyze-set! [ctx [_ obj v :as expr]]
(cond
Expand Down
67 changes: 35 additions & 32 deletions src/sci/impl/resolve.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@
(if sym-ns
(or
#?(:clj
(when (and (= 1 (.length sym-name-str))
(Character/isDigit (.charAt sym-name-str 0)))
(when-let [clazz (interop/resolve-array-class ctx sym-ns sym-name-str)]
[sym clazz])))
(when-not only-var?
(when (and (= 1 (.length sym-name-str))
(Character/isDigit (.charAt sym-name-str 0)))
(when-let [clazz (interop/resolve-array-class ctx sym-ns sym-name-str)]
[sym clazz]))))
(when
#?(:clj (= 'clojure.core sym-ns)
:cljs (or (= 'clojure.core sym-ns)
Expand Down Expand Up @@ -167,35 +168,37 @@
(or
(when-let [[k v]
(find bindings sym)]
(let [idx (or (get (:iden->invoke-idx ctx) v)
(let [oi (:outer-idens ctx)
ob (oi v)]
(update-parents ctx (:closure-bindings ctx) ob)))
#?@(:clj [tag (or (:tag m)
(some-> k meta :tag))])
mutable? (when track-mutable?
(when-let [m (some-> k meta)]
#?(:clj (or (:volatile-mutable m)
(:unsynchronized-mutable m))
:cljs (or (:mutable m)
(:volatile-mutable m)))))
v (if call? ;; resolve-symbol is already handled in the call case
(mark-resolve-sym k idx)
(let [v (cond-> (if mutable?
(let [ext-map (second (lookup ctx '__sci_this false))]
(if only-var?
[k nil]
(let [idx (or (get (:iden->invoke-idx ctx) v)
(let [oi (:outer-idens ctx)
ob (oi v)]
(update-parents ctx (:closure-bindings ctx) ob)))
#?@(:clj [tag (or (:tag m)
(some-> k meta :tag))])
mutable? (when track-mutable?
(when-let [m (some-> k meta)]
#?(:clj (or (:volatile-mutable m)
(:unsynchronized-mutable m))
:cljs (or (:mutable m)
(:volatile-mutable m)))))
v (if call? ;; resolve-symbol is already handled in the call case
(mark-resolve-sym k idx)
(let [v (cond-> (if mutable?
(let [ext-map (second (lookup ctx '__sci_this false))]
(->Node
(let [this (sci.impl.types/eval ext-map ctx bindings)
inner (sci.impl.types/getVal this)]
(get inner sym))
nil))
(->Node
(let [this (sci.impl.types/eval ext-map ctx bindings)
inner (sci.impl.types/getVal this)]
(get inner sym))
nil))
(->Node
(aget ^objects bindings idx)
nil))
#?@(:clj [tag (with-meta
{:tag tag})])
mutable? (vary-meta assoc :mutable true))]
v))]
[k v]))
(aget ^objects bindings idx)
nil))
#?@(:clj [tag (with-meta
{:tag tag})])
mutable? (vary-meta assoc :mutable true))]
v))]
[k v])))
(when-let [kv (lookup* ctx sym call? only-var?)]
(when (:check-permissions ctx)
(check-permission! ctx sym kv))
Expand Down
5 changes: 4 additions & 1 deletion test/sci/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,10 @@
#?(:clj (is (nil? (sci/eval-string "(resolve 'java.lang.Exception/foo)"
{:classes {'java.lang.Exception java.lang.Exception}})))
:cljs (is (nil? (sci/eval-string "(resolve 'js/Error)" {:classes {'js #js {:Error js/Error}}}))))
(is (= 1 (eval* "((binding [*ns* 'user] (resolve 'inc)) 0)"))))
(is (= 1 (eval* "((binding [*ns* 'user] (resolve 'inc)) 0)")))
(is (= 2 (eval* "(def x 2) (let [x 1 x #'x] @x)")))
(is (thrown-with-msg? Exception #"dude" (eval* "(defn foo [] #'dude)")))
(is (thrown-with-msg? Exception #"inc" (sci/eval-string "(defn foo [] #'inc)" {:deny '[inc]}))))

#?(:clj
(deftest type-hint-let-test
Expand Down
Loading