Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with ns being unavail after in-ns during eval (#718) #727

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fix issue with `with` failing with a traceback error when an exception is thrown (#714).
* 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).

## [v0.1.0a2]
### Added
Expand Down
7 changes: 7 additions & 0 deletions src/basilisp/lang/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,13 @@ def __get_or_create(
if ns is not None:
return ns_cache
new_ns = Namespace(name, module=module)
# The `ns` macro is important for setting up an new namespace,
# but it becomes available only after basilisp.core has been
# loaded.
ns_var = Var.find_in_ns(CORE_NS_SYM, sym.symbol("ns"))
if ns_var:
new_ns.add_refer(sym.symbol("ns"), ns_var)

return ns_cache.assoc(name, new_ns)

@classmethod
Expand Down
9 changes: 9 additions & 0 deletions tests/basilisp/namespace_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ def test_create_ns(ns_sym: sym.Symbol, ns_cache: atom.Atom[NamespaceMap]):
assert isinstance(ns, Namespace)
assert ns.name == ns_sym.name
assert len(list(ns_cache.deref().keys())) == 2
assert ns.get_refer(sym.symbol("ns"))


def test_in_ns(ns_sym: sym.Symbol):
in_ns = Var.find_in_ns(runtime.CORE_NS_SYM, sym.symbol("in-ns"))
assert in_ns
ns = in_ns.value(ns_sym)
assert isinstance(ns, Namespace)
assert ns.name == ns_sym.name


@pytest.fixture
Expand Down
12 changes: 12 additions & 0 deletions tests/basilisp/test_core_fns.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -2010,3 +2010,15 @@
[:a2 "and this one!"]]
@a2-atom))
(is (= [] @b-atom))))


;;;;;;;;;;
;; eval ;;
;;;;;;;;;;

(deftest eval-test
(testing "can ns after in-ns"
(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))))))
Loading