Skip to content

Commit

Permalink
Do not attempt to resolve symbols in data reader tags (#1132)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chrisrink10 authored Nov 20, 2024
1 parent 7cdadd2 commit 60e9e09
Show file tree
Hide file tree
Showing 3 changed files with 258 additions and 213 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

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

## [v0.3.2]
### Added
Expand Down
6 changes: 3 additions & 3 deletions src/basilisp/lang/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ def _read_byte_str(ctx: ReaderContext) -> bytes:


@_with_loc
def _read_sym(ctx: ReaderContext) -> MaybeSymbol:
def _read_sym(ctx: ReaderContext, is_reader_macro_sym: bool = False) -> MaybeSymbol:
"""Return a symbol from the input stream.
If a symbol appears in a syntax quoted form, the reader will attempt
Expand Down Expand Up @@ -1065,7 +1065,7 @@ def _read_sym(ctx: ReaderContext) -> MaybeSymbol:
return False
elif name == "&":
return _AMPERSAND
if ctx.is_syntax_quoted and not name.endswith("#"):
if ctx.is_syntax_quoted and not name.endswith("#") and not is_reader_macro_sym:
return ctx.resolve(sym.symbol(name, ns))
return sym.symbol(name, ns=ns)

Expand Down Expand Up @@ -1670,7 +1670,7 @@ def _read_reader_macro(ctx: ReaderContext) -> LispReaderForm: # noqa: MC0001
elif char == "#":
return _read_numeric_constant(ctx)
elif ns_name_chars.match(char):
s = _read_sym(ctx)
s = _read_sym(ctx, is_reader_macro_sym=True)
assert isinstance(s, sym.Symbol)
if s.ns is None and s.name == "b":
return _read_byte_str(ctx)
Expand Down
Loading

0 comments on commit 60e9e09

Please sign in to comment.