Skip to content

Commit

Permalink
Merge branch 'main' into feat/print-cause-trace
Browse files Browse the repository at this point in the history
  • Loading branch information
ikappaki authored Dec 14, 2023
2 parents 6b40eb8 + 14689d6 commit 784d65c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fix issue with `sort-*` family of funtions returning an error on an empty seq (#716).
* Fix issue with `intern` failing when used (#725).
* Fix issue with `ns` not being available after `in-ns` on the REPL (#718).
* Fixed issue with import modules aliasing using ns eval (#719).
* Fix issue with `ns-resolve` throwing an error on macros (#720).

## [v0.1.0a2]
### Added
Expand Down
8 changes: 7 additions & 1 deletion src/basilisp/core.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -4642,7 +4642,13 @@
Use of ``import`` directly is discouraged in favor of the ``:import`` directive in
the :lpy:fn:`ns` macro."
[& modules]
`(import* ~@modules))
;; We need to use eval here, because there could have been an ns
;; switch inside an eval earlier, and although *ns* is correctly set
;; to the new ns, the global python namespace can still refer to the
;; old python global ns where the import would have been evaluated
;; otherwise.
(let [form `(import* ~@modules)]
`(eval '~form *ns*)))

(defn ^:private rewrite-clojure-libspec
"Rewrite libspecs which point to namespaces starting with 'clojure.' to use a
Expand Down
3 changes: 2 additions & 1 deletion src/basilisp/lang/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,8 @@ def resolve_alias(s: sym.Symbol, ns: Optional[Namespace] = None) -> sym.Symbol:
def resolve_var(s: sym.Symbol, ns: Optional[Namespace] = None) -> Optional[Var]:
"""Resolve the aliased symbol to a Var from the specified namespace, or the
current namespace if none is specified."""
return Var.find(resolve_alias(s, ns))
ns_qualified_sym = resolve_alias(s, ns)
return Var.find(resolve_alias(s, ns)) if ns_qualified_sym.ns else None


#######################
Expand Down
23 changes: 22 additions & 1 deletion tests/basilisp/test_core_fns.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,21 @@
;; a valid symbol in that namespace
(is (= (resolve 'basilisp.shell/sh) (requiring-resolve 'basilisp.shell/sh))))

(deftest ns-resolve-test
(is (= #'basilisp.core/apply (ns-resolve *ns* 'apply)))
(is (nil? (ns-resolve *ns* 'xyz)))

(is (= #'basilisp.set/union (ns-resolve *ns* 'basilisp.set/union)))
(is (= #'basilisp.set/union (ns-resolve *ns* 'set/union)))
(is (nil? (ns-resolve *ns* 'basilisp.set/xyz)))
(is (nil? (ns-resolve *ns* 'set/xyz)))

(is (= #'basilisp.test/is (ns-resolve *ns* 'is)))
(is (nil? (ns-resolve *ns* '*test-section*)))
(is (= #'basilisp.test/*test-section* (ns-resolve (the-ns 'basilisp.test) '*test-section*)))

(is (nil? (ns-resolve *ns* 'if))))

(deftest intern-test
(let [ns-sym (gensym "intern-test-ns")
ns0 (create-ns ns-sym)]
Expand Down Expand Up @@ -2021,4 +2036,10 @@
(binding [*ns* *ns*]
(eval '(in-ns 'test-core-fns.ns-after-in-ns))
(eval '(ns test-core-fns.ns-after-in-ns))
(is (= *ns* (the-ns 'test-core-fns.ns-after-in-ns))))))
(is (= *ns* (the-ns 'test-core-fns.ns-after-in-ns)))))

(testing "eval ns with import aliases"
(binding [*ns* *ns*]
(eval '(ns test-core-fns.ns-with-import (:import [time :as time-alias])))
(is (= *ns* (the-ns 'test-core-fns.ns-with-import)))
(is (= "Thu Jan 1 00:00:01 1970" (eval '(time-alias/asctime (time-alias/gmtime 1))))))))

0 comments on commit 784d65c

Please sign in to comment.