Skip to content

Commit 78d841a

Browse files
authored
Fix issue with ns being unavail after in-ns during eval (#718) (#727)
Hi can you please review patch to fix the problem of `ns` becoming unavailable after executing `in-ns` in the context of the `eval` operation. It addresses #718. (part of breaking the individual bugfixes from #723) thanks Co-authored-by: ikappaki <[email protected]>
1 parent 8a42054 commit 78d841a

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
* Fix issue with `with` failing with a traceback error when an exception is thrown (#714).
1515
* Fix issue with `sort-*` family of funtions returning an error on an empty seq (#716).
1616
* Fix issue with `intern` failing when used (#725).
17+
* Fix issue with `ns` not being available after `in-ns` on the REPL (#718).
1718

1819
## [v0.1.0a2]
1920
### Added

src/basilisp/lang/runtime.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,13 @@ def __get_or_create(
768768
if ns is not None:
769769
return ns_cache
770770
new_ns = Namespace(name, module=module)
771+
# The `ns` macro is important for setting up an new namespace,
772+
# but it becomes available only after basilisp.core has been
773+
# loaded.
774+
ns_var = Var.find_in_ns(CORE_NS_SYM, sym.symbol("ns"))
775+
if ns_var:
776+
new_ns.add_refer(sym.symbol("ns"), ns_var)
777+
771778
return ns_cache.assoc(name, new_ns)
772779

773780
@classmethod

tests/basilisp/namespace_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ def test_create_ns(ns_sym: sym.Symbol, ns_cache: atom.Atom[NamespaceMap]):
3232
assert isinstance(ns, Namespace)
3333
assert ns.name == ns_sym.name
3434
assert len(list(ns_cache.deref().keys())) == 2
35+
assert ns.get_refer(sym.symbol("ns"))
36+
37+
38+
def test_in_ns(ns_sym: sym.Symbol):
39+
in_ns = Var.find_in_ns(runtime.CORE_NS_SYM, sym.symbol("in-ns"))
40+
assert in_ns
41+
ns = in_ns.value(ns_sym)
42+
assert isinstance(ns, Namespace)
43+
assert ns.name == ns_sym.name
3544

3645

3746
@pytest.fixture

tests/basilisp/test_core_fns.lpy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,3 +2010,15 @@
20102010
[:a2 "and this one!"]]
20112011
@a2-atom))
20122012
(is (= [] @b-atom))))
2013+
2014+
2015+
;;;;;;;;;;
2016+
;; eval ;;
2017+
;;;;;;;;;;
2018+
2019+
(deftest eval-test
2020+
(testing "can ns after in-ns"
2021+
(binding [*ns* *ns*]
2022+
(eval '(in-ns 'test-core-fns.ns-after-in-ns))
2023+
(eval '(ns test-core-fns.ns-after-in-ns))
2024+
(is (= *ns* (the-ns 'test-core-fns.ns-after-in-ns))))))

0 commit comments

Comments
 (0)