Skip to content

Commit 08f7696

Browse files
authored
Allow def names without reader metadata by default (#861)
Fixes #850
1 parent 6b3a053 commit 08f7696

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
* Fix a bug where `basilisp.lang.compiler.exception.CompilerException` would nearly always suppress line information in it's `data` map (#845)
1818
* Fix a bug where the function returned by `partial` retained the meta, arities, and `with_meta` method of the wrapped function rather than creating new ones (#847)
1919
* Fix a bug where exceptions arising while reading reader conditional forms did not include line and column information (#854)
20+
* Fix a bug where names `def`'ed without reader metadata would cause the compiler to throw an exception (#850)
2021

2122
## [v0.1.0b1]
2223
### Added

src/basilisp/lang/compiler/analyzer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,9 @@ def _def_ast( # pylint: disable=too-many-locals,too-many-statements
954954
def_loc = _loc(form) or _loc(name) or (None, None)
955955
if def_loc == (None, None):
956956
logger.warning(f"def line and column metadata not provided for Var {name}")
957+
if name.meta is None:
958+
logger.warning(f"def name symbol has no metadata for Var {name}")
959+
name = name.with_meta(lmap.EMPTY)
957960
def_node_env = ctx.get_node_env(pos=ctx.syntax_position)
958961
def_meta = _clean_meta(
959962
name.meta.update( # type: ignore [union-attr]

tests/basilisp/compiler_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,17 @@ def test_def_unbound(self, lcompile: CompileFn, ns: runtime.Namespace):
259259
assert var.root == runtime.Unbound(var)
260260
assert not var.is_bound
261261

262+
def test_def_name_with_no_metadata(
263+
self, lcompile: CompileFn, ns: runtime.Namespace
264+
):
265+
var = lcompile(
266+
"""
267+
(defmacro defxyz [v] `(def ~(symbol "xyz") ~v))
268+
(defxyz :val)
269+
"""
270+
)
271+
assert var.root == kw.keyword("val")
272+
262273
def test_recursive_def(self, lcompile: CompileFn, ns: runtime.Namespace):
263274
lcompile("(def a a)")
264275
var = Var.find_in_ns(sym.symbol(ns.name), sym.symbol("a"))

0 commit comments

Comments
 (0)