Repair latent error of mismatched key types

This commit is contained in:
Tony Garnock-Jones 2024-04-09 14:49:45 +02:00
parent 86b74cd807
commit 3bbad3df6d
1 changed files with 4 additions and 2 deletions

View File

@ -345,13 +345,15 @@
[(key (in-list path))]
(step-term term key)))
(define (index? k) (exact-nonnegative-integer? k))
(define (step-term term key)
(cond [(non-object-struct? term)
(define v (struct->vector term))
(define k (+ key 1)) ;; skip the label
(if (>= k (vector-length v)) (void) (vector-ref v k))]
(when (and (index? k) (< k (vector-length v))) (vector-ref v k))]
[(list? term)
(if (>= key (length term)) (void) (list-ref term key))]
(when (and (index? key) (< key (length term))) (list-ref term key))]
[(hash? term)
(hash-ref term key (void))]
[else