Skip to content

Commit c21e7f3

Browse files
committed
it appears that the check for empty list when the depth is 'unknown-mismatch-depth was overzealous
The way that things work, as soon as there is something in the one of the nested lists that needs to be checked to make sure they are different, then we're going to get the correct depth in `nesting-depth` closes #268
1 parent ac38ebd commit c21e7f3

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

redex-lib/redex/private/matcher.rkt

+11-18
Original file line numberDiff line numberDiff line change
@@ -690,24 +690,17 @@ See match-a-pattern.rkt for more details
690690
(define table (make-hash))
691691
(hash-set! mismatch-ht name table)
692692
(set! priors table))
693-
(cond
694-
[(equal? nesting-depth 'unknown-mismatch-depth)
695-
(unless (null? exp)
696-
(error 'matcher.rkt
697-
(string-append "invariant broken; unknown-mismatch-depth should"
698-
" appear only when the expression is an empty list: ~s")
699-
exp))]
700-
[else
701-
(let loop ([depth nesting-depth]
702-
[exp exp])
703-
(cond
704-
[(= depth 0)
705-
(when (hash-ref priors exp #f)
706-
(fail #f))
707-
(hash-set! priors exp #t)]
708-
[else
709-
(for ([exp-ele (in-list exp)])
710-
(loop (- depth 1) exp-ele))]))])]))
693+
(unless (equal? nesting-depth 'unknown-mismatch-depth)
694+
(let loop ([depth nesting-depth]
695+
[exp exp])
696+
(cond
697+
[(= depth 0)
698+
(when (hash-ref priors exp #f)
699+
(fail #f))
700+
(hash-set! priors exp #t)]
701+
[else
702+
(for ([exp-ele (in-list exp)])
703+
(loop (- depth 1) exp-ele))])))]))
711704
(make-bindings (hash-map match-ht make-bind)))))
712705

713706
;; compile-pattern : compiled-lang pattern boolean -> compiled-pattern

redex-test/redex/tests/matcher-test.rkt

+24
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,30 @@
176176
(make-bind '..._1 2)))
177177
'(1 1 1 1 2 2)
178178
none)))
179+
(test-empty '(list (repeat (list (repeat (mismatch-name number_!_ number) #f #f)) #f #f))
180+
'(())
181+
(list (make-mtch (make-bindings '()) '(()) none)))
182+
(test-empty '(list (repeat (list (repeat (mismatch-name number_!_ number) #f #f)) #f #f))
183+
'(() ())
184+
(list (make-mtch (make-bindings '()) '(() ()) none)))
185+
(test-empty '(list (repeat (list (repeat (list (repeat (mismatch-name number_!_ number) #f #f)) #f #f)) #f #f))
186+
'(() ())
187+
(list (make-mtch (make-bindings '()) '(() ()) none)))
188+
(test-empty '(list (repeat (list (repeat (list (repeat (mismatch-name number_!_ number) #f #f)) #f #f)) #f #f))
189+
'(() (()))
190+
(list (make-mtch (make-bindings '()) '(() (())) none)))
191+
(test-empty '(list (repeat (list (repeat (list (repeat (mismatch-name number_!_ number) #f #f)) #f #f)) #f #f))
192+
'(() ((())))
193+
#f)
194+
(test-empty '(list (repeat (list (repeat (list (repeat (mismatch-name number_!_ number) #f #f)) #f #f)) #f #f))
195+
'(() ((1)))
196+
(list (make-mtch (make-bindings '()) '(() ((1))) none)))
197+
(test-empty '(list (repeat (list (repeat (list (repeat (mismatch-name number_!_ number) #f #f)) #f #f)) #f #f))
198+
'(() (()))
199+
(list (make-mtch (make-bindings '()) '(() (())) none)))
200+
(test-empty '(list (repeat (list (repeat (list (repeat (mismatch-name number_!_ number) #f #f)) #f #f)) #f #f))
201+
'(() (1))
202+
#f)
179203

180204
(test-ellipses '(a) '(a))
181205
(test-ellipses '((repeat a #f #f)) `(,(make-repeat 'a '() #f #f)))

0 commit comments

Comments
 (0)