From 9325793ae16af37abcd4b69c49c14e93292101f6 Mon Sep 17 00:00:00 2001 From: Yiran Lu Date: Thu, 24 Oct 2024 23:38:38 +0200 Subject: [PATCH 1/2] make `_dotted` condition stricter --- hyrule/argmove.hy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hyrule/argmove.hy b/hyrule/argmove.hy index 94f55fbc..ce69d488 100644 --- a/hyrule/argmove.hy +++ b/hyrule/argmove.hy @@ -11,7 +11,8 @@ also known as arrow macros." (defn _dotted [node] "Helper function to turn '.name forms into '(.name) forms" (if (and (isinstance node hy.models.Expression) - (= (get node 0) '.)) + (= (get node 0) '.) + (is (get node 1) None)) `(~node) node))) From f71136d09f32f70e81a0a8b2bb6d646a9f7f25be Mon Sep 17 00:00:00 2001 From: Yiran Lu Date: Fri, 25 Oct 2024 11:11:31 +0200 Subject: [PATCH 2/2] fixes `_dotted` condition --- hyrule/argmove.hy | 2 +- tests/test_argmove.hy | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/hyrule/argmove.hy b/hyrule/argmove.hy index ce69d488..4851379b 100644 --- a/hyrule/argmove.hy +++ b/hyrule/argmove.hy @@ -12,7 +12,7 @@ also known as arrow macros." "Helper function to turn '.name forms into '(.name) forms" (if (and (isinstance node hy.models.Expression) (= (get node 0) '.) - (is (get node 1) None)) + (= (get node 1) 'None)) `(~node) node))) diff --git a/tests/test_argmove.hy b/tests/test_argmove.hy index 66fd4032..27cfa852 100644 --- a/tests/test_argmove.hy +++ b/tests/test_argmove.hy @@ -24,6 +24,15 @@ (->> ["foo"] (* 10) (.join ", ") .split)))) +(defn test-threading-dotted-properties [] + (defclass A [] + (defn __init__ [self] + (setv self.a 1))) + (setv x (A)) + (assert (= x.a + (-> x (. a))))) + + (defn test-threading-in-macro [] ; https://github.com/hylang/hy/issues/1537 ; The macros need to be defined in another file or else the bug