Skip to content

Commit

Permalink
Merge pull request #2626 from Kodiologist/dot-empty
Browse files Browse the repository at this point in the history
Fix the handling of dot expressions with ""
  • Loading branch information
Kodiologist authored Jan 11, 2025
2 parents 2d286a6 + b06d438 commit 0645722
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ New Features
------------------------------
* New pragma `hy`.

Bug Fixes
------------------------------
* Fixed a crash from using an empty string in a `(. …)` expression.

1.0.0 ("Afternoon Review", released 2024-09-22)
======================================================================

Expand Down
6 changes: 5 additions & 1 deletion hy/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,11 @@ def macroexpand(tree, module, compiler=None, once=False, result_ok=True):
while isinstance(tree, Expression) and tree:

fn = tree[0]
if isinstance(fn, Expression) and fn and fn[0] == Symbol("."):
if (
isinstance(fn, Expression) and
fn and
fn[0] == Symbol(".") and
all(isinstance(x, Symbol) for x in fn)):
fn = ".".join(map(mangle, fn[1:]))
elif isinstance(fn, Symbol):
fn = mangle(fn)
Expand Down
8 changes: 8 additions & 0 deletions tests/native_tests/dots.hy
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
(assert (= (.__str__ :foo) ":foo")))


(defn test-dot-empty-string []
; https://github.com/hylang/hy/issues/2625
(assert (=
((. "" join) ["aa" "bb" "cc"])
(.join "" ["aa" "bb" "cc"])
"aabbcc")))


(defn test-dot-macro []
(defclass mycls [object])

Expand Down

0 comments on commit 0645722

Please sign in to comment.