Skip to content

Commit 60e9e09

Browse files
authored
Do not attempt to resolve symbols in data reader tags (#1132)
Fixes #1129 For anyone who finds this PR (perhaps triaging a bug introduced by it in the future): I tried to ascertain exactly what Clojure JVM does in this situation and it is quite unclear in the reader code and not (at the time of writing) specified on any of the official documentation. Examples given there seem to indicate that fully qualified tags be given in `data_readers.cljc` and thus symbol resolution should not be performed on them, but they don't say explicitly. CLJS `#js []` literals work as they do now in this PR so I'm going to assume this is the intended behavior.
1 parent 7cdadd2 commit 60e9e09

File tree

3 files changed

+258
-213
lines changed

3 files changed

+258
-213
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed
9+
* Fix a bug where tags in data readers were resolved as Vars within syntax quotes, rather than using standard data readers rules (#1129)
810

911
## [v0.3.2]
1012
### Added

src/basilisp/lang/reader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ def _read_byte_str(ctx: ReaderContext) -> bytes:
10361036

10371037

10381038
@_with_loc
1039-
def _read_sym(ctx: ReaderContext) -> MaybeSymbol:
1039+
def _read_sym(ctx: ReaderContext, is_reader_macro_sym: bool = False) -> MaybeSymbol:
10401040
"""Return a symbol from the input stream.
10411041
10421042
If a symbol appears in a syntax quoted form, the reader will attempt
@@ -1065,7 +1065,7 @@ def _read_sym(ctx: ReaderContext) -> MaybeSymbol:
10651065
return False
10661066
elif name == "&":
10671067
return _AMPERSAND
1068-
if ctx.is_syntax_quoted and not name.endswith("#"):
1068+
if ctx.is_syntax_quoted and not name.endswith("#") and not is_reader_macro_sym:
10691069
return ctx.resolve(sym.symbol(name, ns))
10701070
return sym.symbol(name, ns=ns)
10711071

@@ -1670,7 +1670,7 @@ def _read_reader_macro(ctx: ReaderContext) -> LispReaderForm: # noqa: MC0001
16701670
elif char == "#":
16711671
return _read_numeric_constant(ctx)
16721672
elif ns_name_chars.match(char):
1673-
s = _read_sym(ctx)
1673+
s = _read_sym(ctx, is_reader_macro_sym=True)
16741674
assert isinstance(s, sym.Symbol)
16751675
if s.ns is None and s.name == "b":
16761676
return _read_byte_str(ctx)

0 commit comments

Comments
 (0)