Skip to content

Commit 31b4804

Browse files
committed
Fix the handling of dot expressions with ""
1 parent 647b423 commit 31b4804

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

NEWS.rst

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ New Features
99
------------------------------
1010
* New pragma `hy`.
1111

12+
Bug Fixes
13+
------------------------------
14+
* Fixed a crash from using an empty string in a `(. …)` expression.
15+
1216
1.0.0 ("Afternoon Review", released 2024-09-22)
1317
======================================================================
1418

hy/macros.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,11 @@ def macroexpand(tree, module, compiler=None, once=False, result_ok=True):
357357
while isinstance(tree, Expression) and tree:
358358

359359
fn = tree[0]
360-
if isinstance(fn, Expression) and fn and fn[0] == Symbol("."):
360+
if (
361+
isinstance(fn, Expression) and
362+
fn and
363+
fn[0] == Symbol(".") and
364+
all(isinstance(x, Symbol) for x in fn)):
361365
fn = ".".join(map(mangle, fn[1:]))
362366
elif isinstance(fn, Symbol):
363367
fn = mangle(fn)

tests/native_tests/dots.hy

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@
3535
(assert (= (.__str__ :foo) ":foo")))
3636

3737

38+
(defn test-dot-empty-string []
39+
; https://github.com/hylang/hy/issues/2625
40+
(assert (=
41+
((. "" join) ["aa" "bb" "cc"])
42+
(.join "" ["aa" "bb" "cc"])
43+
"aabbcc")))
44+
45+
3846
(defn test-dot-macro []
3947
(defclass mycls [object])
4048

0 commit comments

Comments
 (0)