diff --git a/pkgs/redex-pkgs/redex-lib/redex/private/matcher.rkt b/pkgs/redex-pkgs/redex-lib/redex/private/matcher.rkt index 7c2cfb5af8..eef56b7af8 100644 --- a/pkgs/redex-pkgs/redex-lib/redex/private/matcher.rkt +++ b/pkgs/redex-pkgs/redex-lib/redex/private/matcher.rkt @@ -682,16 +682,24 @@ See match-a-pattern.rkt for more details (define table (make-hash)) (hash-set! mismatch-ht name table) (set! priors table)) - (let loop ([depth nesting-depth] - [exp exp]) - (cond - [(= depth 0) - (when (hash-ref priors exp #f) - (fail #f)) - (hash-set! priors exp #t)] - [else - (for ([exp-ele (in-list exp)]) - (loop (- depth 1) exp-ele))]))])) + (cond + [(equal? nesting-depth 'unknown-mismatch-depth) + (unless (null? exp) + (error 'matcher.rkt + (string-append "invariant broken; unknown-mismatch-depth should" + " appear only when the expression is an empty list: ~s") + exp))] + [else + (let loop ([depth nesting-depth] + [exp exp]) + (cond + [(= depth 0) + (when (hash-ref priors exp #f) + (fail #f)) + (hash-set! priors exp #t)] + [else + (for ([exp-ele (in-list exp)]) + (loop (- depth 1) exp-ele))]))])])) (make-mtch (make-bindings (hash-map match-ht make-bind)) (mtch-context match) diff --git a/pkgs/redex-pkgs/redex-test/redex/tests/matcher-test.rkt b/pkgs/redex-pkgs/redex-test/redex/tests/matcher-test.rkt index d90addc37c..228631c84e 100644 --- a/pkgs/redex-pkgs/redex-test/redex/tests/matcher-test.rkt +++ b/pkgs/redex-pkgs/redex-test/redex/tests/matcher-test.rkt @@ -143,6 +143,9 @@ (repeat (mismatch-name number_!_1 number) #f #f)) '((1 2) (3 4) 5 6) (list (make-test-mtch (make-bindings (list)) '((1 2) (3 4) 5 6) none))) + (test-empty '(list (repeat (mismatch-name number_!_1 number) #f #f)) + '() + (list (make-test-mtch (make-bindings (list)) '() none))) (test-empty '(list (repeat (name x_1 1) ..._1 ..._!_1) (repeat (name x_1 1) ..._1 #f)