From 81715deb567a159997e3a774883f1910074ee0dc Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 17 Dec 2023 19:09:22 -0800 Subject: txr: bug in handling @{nil ...} variable match. In March 2012, b7f1f4c5bbea86e288b6a4d68595c1d2d07217bd introduced the feature that the @nil variable matches and discards. This was incompletely implemented. Some cases of a nil variable with modifiers fail to match. * match.c (dest_bind): This function must correctly handle the case when pattern is nil: it should just return bindings without extending them. If the pattern is any nonbindable symbol, it should indicate a failed match using t. The logic has not been touched since 2009, at which time an additional bogosity was introduced of calling funcall(testfun, pattern, value) when pattern is a non-bindable symbol. If value is a string, that could never work. Possibly the idea is that the value could come from a symbol-valued expression, such as one producing a keyword symbol. We are not going to support that, unless someone complains. * tests/000/nilvar.txr, tests/000/nilvar.expected: New files, providing a test case that fails without this commit. --- match.c | 4 +++- tests/000/nilvar.expected | 1 + tests/000/nilvar.txr | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 tests/000/nilvar.expected create mode 100644 tests/000/nilvar.txr diff --git a/match.c b/match.c index 0bc40838..0f1583f1 100644 --- a/match.c +++ b/match.c @@ -381,8 +381,10 @@ static val dest_bind(val spec, val bindings, val pattern, return t; } return cons(cons(pattern, value), bindings); + } else if (pattern) { + return t; } else { - return funcall2(testfun, pattern, value) ? bindings : t; + return bindings; } } else if (consp(pattern)) { val piter = pattern, viter = value; diff --git a/tests/000/nilvar.expected b/tests/000/nilvar.expected new file mode 100644 index 00000000..70985094 --- /dev/null +++ b/tests/000/nilvar.expected @@ -0,0 +1 @@ +a:c diff --git a/tests/000/nilvar.txr b/tests/000/nilvar.txr new file mode 100644 index 00000000..a6d1391c --- /dev/null +++ b/tests/000/nilvar.txr @@ -0,0 +1,3 @@ +@(next :string "a !b c") +@(coll)@(cases)@{nil /!\S+/}@(or)@{var /\S+/}@(end)@(end) +@(do (put-line (join-with ":" var))) -- cgit v1.2.3