From b06d43884d7f924162ac5698d3b215f4004395e7 Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Tue, 7 Jan 2025 13:13:21 -0500 Subject: [PATCH] Fix the handling of dot expressions with "" --- NEWS.rst | 4 ++++ hy/macros.py | 6 +++++- tests/native_tests/dots.hy | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/NEWS.rst b/NEWS.rst index e82b571da..603eea0ed 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -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) ====================================================================== diff --git a/hy/macros.py b/hy/macros.py index ef591523c..afc764e25 100644 --- a/hy/macros.py +++ b/hy/macros.py @@ -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) diff --git a/tests/native_tests/dots.hy b/tests/native_tests/dots.hy index ef3ae3c66..76a047ad2 100644 --- a/tests/native_tests/dots.hy +++ b/tests/native_tests/dots.hy @@ -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])