summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-05-11 07:48:12 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-05-11 07:48:12 -0700
commita11a36d50d17e4cc3f1b6eec252156dd6201beef (patch)
treecc3d601a1da01eb92f1eac5fa7bac35b0710836c
parentb7f563787f101aa42612a7297c6874e77cb01748 (diff)
downloadtxr-a11a36d50d17e4cc3f1b6eec252156dd6201beef.tar.gz
txr-a11a36d50d17e4cc3f1b6eec252156dd6201beef.tar.bz2
txr-a11a36d50d17e4cc3f1b6eec252156dd6201beef.zip
lambda-match: bug: over-strict match in variadic pattern.
* stdlib/match.tl (expand-lambda-match): A pattern that is shorter than the maximum number of arguments is augmented with a check ensuring that no fixed arguments are present beyond those that the pattern requires. However, this check must be omitted if the pattern is variadic, because those excess arguments match its tail pattern. * tests/011/patmatch.tl: Cases added.
-rw-r--r--stdlib/match.tl2
-rw-r--r--tests/011/patmatch.tl14
2 files changed, 15 insertions, 1 deletions
diff --git a/stdlib/match.tl b/stdlib/match.tl
index 17870be2..55d50417 100644
--- a/stdlib/match.tl
+++ b/stdlib/match.tl
@@ -782,7 +782,7 @@
(when (> pc.nfixed min-args)
(set exp ^(when ,[present-vec (pred pc.nfixed)]
,exp)))
- (when (< pc.nfixed max-args)
+ (when (and (not vp) (< pc.nfixed max-args))
(set exp ^(unless ,[present-vec pc.nfixed]
,exp)))
(when (and variadic (not vp) (= pc.nfixed max-args))
diff --git a/tests/011/patmatch.tl b/tests/011/patmatch.tl
index 08bcd0f7..81cda935 100644
--- a/tests/011/patmatch.tl
+++ b/tests/011/patmatch.tl
@@ -247,6 +247,20 @@
((@x @y) :no-match)) 1 2 3]
:error)))
+(test
+ [(lambda-match
+ ((@a @b) (list a b))
+ ((@x . @y) (list x y)))
+ 1 2 3]
+ (1 (2 3)))
+
+(test
+ [(lambda-match
+ ((@a @b) (list a b))
+ (@x x))
+ 1 2 3]
+ (1 2 3))
+
(defun-match fib
((0) 1)
((1) 1)