diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-02-08 07:06:30 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-02-08 07:06:30 -0800 |
commit | 3483c7812cb4c8e279088c0f1d78d5c69061083c (patch) | |
tree | 52d1630fe483601db7bce3b8dd9ddcb097974625 | |
parent | d83458347c3730cd804930ad2861178a72d42cde (diff) | |
download | txr-3483c7812cb4c8e279088c0f1d78d5c69061083c.tar.gz txr-3483c7812cb4c8e279088c0f1d78d5c69061083c.tar.bz2 txr-3483c7812cb4c8e279088c0f1d78d5c69061083c.zip |
matcher: fix backreferencing in predicate.
* share/txr/stdlib/match.tl (compile-predicate-match): Always
allocate res-var as a gensym; do not use resvar. Otherwise we
will freshly bind resvar as a local, failing to back-reference.
* tests/011/patmatch.tl: Add test cases, the second of which
fails before this change.
-rw-r--r-- | share/txr/stdlib/match.tl | 2 | ||||
-rw-r--r-- | tests/011/patmatch.tl | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/share/txr/stdlib/match.tl b/share/txr/stdlib/match.tl index 0aea24b2..a1222c5a 100644 --- a/share/txr/stdlib/match.tl +++ b/share/txr/stdlib/match.tl @@ -288,7 +288,7 @@ (let ((sym (cadr vm))) (set args (append (ldiff args vm) sym)) sym)))) - (res-var (if rvar rvar (gensym "res-"))) + (res-var (gensym "res-")) (arg-var (if avar avar (gensym "obj-")))) (unless avar (set args (append args (list arg-var)))) diff --git a/tests/011/patmatch.tl b/tests/011/patmatch.tl index a616b9d2..f49b115d 100644 --- a/tests/011/patmatch.tl +++ b/tests/011/patmatch.tl @@ -94,6 +94,12 @@ (t (1 2 3))) (test (when-match @(@x (< . @sym)) '(3 2 1) (list x sym)) nil) +(test (let ((x t)) + (when-match @(@x (< . @sym)) '(1 2 3) (list x sym))) + (t (1 2 3))) +(test (let ((x nil)) + (when-match @(@x (< . @sym)) '(1 2 3) (list x sym))) + nil) (test (if-match (@(or @a) @a) '(1 2) a :no) :no) (test (if-match (@(and @a) @a) '(1 2) a :no) :no) |