Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
CLJ-2907: Add file source metadata to namespaces
Namespaces created with `ns` will now have `:file`, `:line`, and `:column`
added, when the `:file` is not `NO_SOURCE_PATH` (indicating a repl session or
similar).
  • Loading branch information
NoahTheDuke committed May 20, 2025
commit 2c67372a125fc5d0fe223543d44afe407eb7b83f
6 changes: 6 additions & 0 deletions src/clj/clojure/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5849,6 +5849,12 @@
name)
metadata (when (map? (first references)) (first references))
references (if metadata (next references) references)
form-metadata (meta &form)
metadata (merge (when (not= "NO_SOURCE_PATH" *file*)
{:line (:line form-metadata)
:column (:column form-metadata)
:file *file*})
metadata)
name (if metadata
(vary-meta name merge metadata)
name)
Expand Down
6 changes: 6 additions & 0 deletions test/clojure/test_clojure/ns_libs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
(is (thrown? Exception (use :foo)))
(is (thrown? Exception (use))))

(deftest ns-location-data
(let [ns-meta (meta (the-ns 'clojure.test-clojure.ns-libs))]
(is (contains? ns-meta :line))
(is (contains? ns-meta :column))
(is (contains? ns-meta :file))))

(deftest reimporting-deftypes
(let [inst1 (binding [*ns* *ns*]
(eval '(do (ns exporter)
Expand Down