cs: fix list-{ref,tail} error messages

Closes #3661
This commit is contained in:
Matthew Flatt 2021-01-29 06:28:46 -07:00
parent a7fef69f33
commit b55f268510
5 changed files with 43 additions and 29 deletions

View File

@ -293,11 +293,10 @@
(test 'c list-ref '(a b c . d) 2) (test 'c list-ref '(a b c . d) 2)
(arity-test list-ref 2 2) (arity-test list-ref 2 2)
(err/rt-test (list-ref 1 1) exn:application:mismatch?) (err/rt-test (list-ref 1 1) exn:application:mismatch?)
(err/rt-test (list-ref '(a b . c) 2) exn:application:mismatch?) (err/rt-test (list-ref '(a b . c) 2) exn:application:mismatch? #rx"index reaches a non-pair")
(err/rt-test (list-ref '(1 2 3) 2.0)) (err/rt-test (list-ref '(1 2 3) 2.0))
(err/rt-test (list-ref '(1) '(1))) (err/rt-test (list-ref '(1) '(1)))
(err/rt-test (list-ref '(1) 1) exn:application:mismatch?) (err/rt-test (list-ref '(1) 1) exn:application:mismatch? #rx"index too large for list")
(err/rt-test (list-ref '() 0) exn:application:mismatch?)
(err/rt-test (list-ref '() 0) exn:application:mismatch?) (err/rt-test (list-ref '() 0) exn:application:mismatch?)
(err/rt-test (list-ref '(1) -1)) (err/rt-test (list-ref '(1) -1))
(err/rt-test (list-ref '(1) 2000000000000) exn:application:mismatch?) (err/rt-test (list-ref '(1) 2000000000000) exn:application:mismatch?)
@ -311,8 +310,8 @@
(err/rt-test (list-tail '(1 2 3) 2.0)) (err/rt-test (list-tail '(1 2 3) 2.0))
(err/rt-test (list-tail '(1) '(1))) (err/rt-test (list-tail '(1) '(1)))
(err/rt-test (list-tail '(1) -1)) (err/rt-test (list-tail '(1) -1))
(err/rt-test (list-tail '(1) 2) exn:application:mismatch?) (err/rt-test (list-tail '(1) 2) exn:application:mismatch? #rx"index too large for list")
(err/rt-test (list-tail '(1 2 . 3) 3) exn:application:mismatch?) (err/rt-test (list-tail '(1 2 . 3) 3) exn:application:mismatch? #rx"index reaches a non-pair")
(err/rt-test (car 0) exn:fail:contract? #rx"car: contract violation.*expected: pair[?].*given: 0") (err/rt-test (car 0) exn:fail:contract? #rx"car: contract violation.*expected: pair[?].*given: 0")
(err/rt-test (cdr 0) exn:fail:contract? #rx"cdr: contract violation.*expected: pair[?].*given: 0") (err/rt-test (cdr 0) exn:fail:contract? #rx"cdr: contract violation.*expected: pair[?].*given: 0")

View File

@ -171,8 +171,8 @@
5_2.mo:Expected error in mat c....r-errors: "cddddr: incorrect list structure (a . b)". 5_2.mo:Expected error in mat c....r-errors: "cddddr: incorrect list structure (a . b)".
! 5_2.mo:Expected error in mat list*: "incorrect argument count in call (list*)". ! 5_2.mo:Expected error in mat list*: "incorrect argument count in call (list*)".
! 5_2.mo:Expected error in mat cons*: "incorrect argument count in call (cons*)". ! 5_2.mo:Expected error in mat cons*: "incorrect argument count in call (cons*)".
5_2.mo:Expected error in mat list-ref: "list-ref: a is not a proper list". 5_2.mo:Expected error in mat list-ref: "list-ref: index 0 reaches a non-pair in a".
5_2.mo:Expected error in mat list-ref: "list-ref: (a b . c) is not a proper list". 5_2.mo:Expected error in mat list-ref: "list-ref: index 4 reaches a non-pair in (a b . c)".
5_2.mo:Expected error in mat list-ref: "list-ref: index 4 is out of range for list (a b)". 5_2.mo:Expected error in mat list-ref: "list-ref: index 4 is out of range for list (a b)".
--- 693,700 ---- --- 693,700 ----
5_2.mo:Expected error in mat c....r-errors: "cddadr: incorrect list structure (a . b)". 5_2.mo:Expected error in mat c....r-errors: "cddadr: incorrect list structure (a . b)".
@ -180,8 +180,8 @@
5_2.mo:Expected error in mat c....r-errors: "cddddr: incorrect list structure (a . b)". 5_2.mo:Expected error in mat c....r-errors: "cddddr: incorrect list structure (a . b)".
! 5_2.mo:Expected error in mat list*: "incorrect number of arguments -1 to #<procedure list*>". ! 5_2.mo:Expected error in mat list*: "incorrect number of arguments -1 to #<procedure list*>".
! 5_2.mo:Expected error in mat cons*: "incorrect number of arguments -1 to #<procedure cons*>". ! 5_2.mo:Expected error in mat cons*: "incorrect number of arguments -1 to #<procedure cons*>".
5_2.mo:Expected error in mat list-ref: "list-ref: a is not a proper list". 5_2.mo:Expected error in mat list-ref: "list-ref: index 0 reaches a non-pair in a".
5_2.mo:Expected error in mat list-ref: "list-ref: (a b . c) is not a proper list". 5_2.mo:Expected error in mat list-ref: "list-ref: index 4 reaches a non-pair in (a b . c)".
5_2.mo:Expected error in mat list-ref: "list-ref: index 4 is out of range for list (a b)". 5_2.mo:Expected error in mat list-ref: "list-ref: index 4 is out of range for list (a b)".
*************** ***************
*** 781,793 **** *** 781,793 ****

View File

@ -695,46 +695,46 @@ primvars.mo:Expected error in mat trace-output-port: "trace-output-port: #<input
5_2.mo:Expected error in mat c....r-errors: "cddddr: incorrect list structure (a . b)". 5_2.mo:Expected error in mat c....r-errors: "cddddr: incorrect list structure (a . b)".
5_2.mo:Expected error in mat list*: "incorrect argument count in call (list*)". 5_2.mo:Expected error in mat list*: "incorrect argument count in call (list*)".
5_2.mo:Expected error in mat cons*: "incorrect argument count in call (cons*)". 5_2.mo:Expected error in mat cons*: "incorrect argument count in call (cons*)".
5_2.mo:Expected error in mat list-ref: "list-ref: a is not a proper list". 5_2.mo:Expected error in mat list-ref: "list-ref: index 0 reaches a non-pair in a".
5_2.mo:Expected error in mat list-ref: "list-ref: (a b . c) is not a proper list". 5_2.mo:Expected error in mat list-ref: "list-ref: index 4 reaches a non-pair in (a b . c)".
5_2.mo:Expected error in mat list-ref: "list-ref: index 4 is out of range for list (a b)". 5_2.mo:Expected error in mat list-ref: "list-ref: index 4 is out of range for list (a b)".
5_2.mo:Expected error in mat list-ref: "list-ref: index 4 is out of range for list (a b c)". 5_2.mo:Expected error in mat list-ref: "list-ref: index 4 is out of range for list (a b c)".
5_2.mo:Expected error in mat list-ref: "list-ref: index 4 is out of range for list (a b c d)". 5_2.mo:Expected error in mat list-ref: "list-ref: index 4 is out of range for list (a b c d)".
5_2.mo:Expected error in mat list-ref: "list-ref: (a b c . e) is not a proper list". 5_2.mo:Expected error in mat list-ref: "list-ref: index 4 reaches a non-pair in (a b c . e)".
5_2.mo:Expected error in mat list-ref: "list-ref: (a b c d . e) is not a proper list". 5_2.mo:Expected error in mat list-ref: "list-ref: index 4 reaches a non-pair in (a b c d . e)".
5_2.mo:Expected error in mat list-ref: "list-ref: index 5 is out of range for list (a b c d)". 5_2.mo:Expected error in mat list-ref: "list-ref: index 5 is out of range for list (a b c d)".
5_2.mo:Expected error in mat list-ref: "list-ref: index 5 is out of range for list (a b c d e)". 5_2.mo:Expected error in mat list-ref: "list-ref: index 5 is out of range for list (a b c d e)".
5_2.mo:Expected error in mat list-ref: "list-ref: (a b c d e . f) is not a proper list". 5_2.mo:Expected error in mat list-ref: "list-ref: index 5 reaches a non-pair in (a b c d e . f)".
5_2.mo:Expected error in mat list-ref: "list-ref: (a b . c) is not a proper list". 5_2.mo:Expected error in mat list-ref: "list-ref: index 10000 reaches a non-pair in (a b . c)".
5_2.mo:Expected error in mat list-ref: "list-ref: index 10000 is out of range for list (a b c)". 5_2.mo:Expected error in mat list-ref: "list-ref: index 10000 is out of range for list (a b c)".
5_2.mo:Expected error in mat list-ref: "list-ref: (a b . c) is not a proper list". 5_2.mo:Expected error in mat list-ref: "list-ref: index 444444444444444444444444444444444444444444 reaches a non-pair in (a b . c)".
5_2.mo:Expected error in mat list-ref: "list-ref: index 444444444444444444444444444444444444444444 is out of range for list (a b c)". 5_2.mo:Expected error in mat list-ref: "list-ref: index 444444444444444444444444444444444444444444 is out of range for list (a b c)".
5_2.mo:Expected error in mat list-ref: "list-ref: index -1 is not an exact nonnegative integer". 5_2.mo:Expected error in mat list-ref: "list-ref: index -1 is not an exact nonnegative integer".
5_2.mo:Expected error in mat list-ref: "list-ref: index -4444444444444444444444 is not an exact nonnegative integer". 5_2.mo:Expected error in mat list-ref: "list-ref: index -4444444444444444444444 is not an exact nonnegative integer".
5_2.mo:Expected error in mat list-ref: "list-ref: index a is not an exact nonnegative integer". 5_2.mo:Expected error in mat list-ref: "list-ref: index a is not an exact nonnegative integer".
5_2.mo:Expected error in mat list-tail: "list-tail: (a b . c) is not a proper list". 5_2.mo:Expected error in mat list-tail: "list-tail: index 4 reaches a non-pair in (a b . c)".
5_2.mo:Expected error in mat list-tail: "list-tail: (a b c . d) is not a proper list". 5_2.mo:Expected error in mat list-tail: "list-tail: index 4 reaches a non-pair in (a b c . d)".
5_2.mo:Expected error in mat list-tail: "list-tail: (a b . c) is not a proper list". 5_2.mo:Expected error in mat list-tail: "list-tail: index 5 reaches a non-pair in (a b . c)".
5_2.mo:Expected error in mat list-tail: "list-tail: (a b c . d) is not a proper list". 5_2.mo:Expected error in mat list-tail: "list-tail: index 5 reaches a non-pair in (a b c . d)".
5_2.mo:Expected error in mat list-tail: "list-tail: (a b c d . e) is not a proper list". 5_2.mo:Expected error in mat list-tail: "list-tail: index 5 reaches a non-pair in (a b c d . e)".
5_2.mo:Expected error in mat list-tail: "list-tail: index 4 is out of range for list (a)". 5_2.mo:Expected error in mat list-tail: "list-tail: index 4 is out of range for list (a)".
5_2.mo:Expected error in mat list-tail: "list-tail: index 4 is out of range for list (a b)". 5_2.mo:Expected error in mat list-tail: "list-tail: index 4 is out of range for list (a b)".
5_2.mo:Expected error in mat list-tail: "list-tail: index 4 is out of range for list (a b c)". 5_2.mo:Expected error in mat list-tail: "list-tail: index 4 is out of range for list (a b c)".
5_2.mo:Expected error in mat list-tail: "list-tail: index 5 is out of range for list (a b)". 5_2.mo:Expected error in mat list-tail: "list-tail: index 5 is out of range for list (a b)".
5_2.mo:Expected error in mat list-tail: "list-tail: index 5 is out of range for list (a b c)". 5_2.mo:Expected error in mat list-tail: "list-tail: index 5 is out of range for list (a b c)".
5_2.mo:Expected error in mat list-tail: "list-tail: index 5 is out of range for list (a b c d)". 5_2.mo:Expected error in mat list-tail: "list-tail: index 5 is out of range for list (a b c d)".
5_2.mo:Expected error in mat list-tail: "list-tail: (a b . c) is not a proper list". 5_2.mo:Expected error in mat list-tail: "list-tail: index 10000 reaches a non-pair in (a b . c)".
5_2.mo:Expected error in mat list-tail: "list-tail: index 10000 is out of range for list (a b c)". 5_2.mo:Expected error in mat list-tail: "list-tail: index 10000 is out of range for list (a b c)".
5_2.mo:Expected error in mat list-tail: "list-tail: (a b . c) is not a proper list". 5_2.mo:Expected error in mat list-tail: "list-tail: index 444444444444444444444444444444444444444444 reaches a non-pair in (a b . c)".
5_2.mo:Expected error in mat list-tail: "list-tail: index 444444444444444444444444444444444444444444 is out of range for list (a b c)". 5_2.mo:Expected error in mat list-tail: "list-tail: index 444444444444444444444444444444444444444444 is out of range for list (a b c)".
5_2.mo:Expected error in mat list-tail: "list-tail: index -1 is not an exact nonnegative integer". 5_2.mo:Expected error in mat list-tail: "list-tail: index -1 is not an exact nonnegative integer".
5_2.mo:Expected error in mat list-tail: "list-tail: index -4444444444444444444444 is not an exact nonnegative integer". 5_2.mo:Expected error in mat list-tail: "list-tail: index -4444444444444444444444 is not an exact nonnegative integer".
5_2.mo:Expected error in mat list-tail: "list-tail: index a is not an exact nonnegative integer". 5_2.mo:Expected error in mat list-tail: "list-tail: index a is not an exact nonnegative integer".
5_2.mo:Expected error in mat list-head: "list-head: (a . b) is not a proper list". 5_2.mo:Expected error in mat list-head: "list-head: index 3 reaches a non-pair in (a . b)".
5_2.mo:Expected error in mat list-head: "list-head: (a b . c) is not a proper list". 5_2.mo:Expected error in mat list-head: "list-head: index 3 reaches a non-pair in (a b . c)".
5_2.mo:Expected error in mat list-head: "list-head: (a b . c) is not a proper list". 5_2.mo:Expected error in mat list-head: "list-head: index 4 reaches a non-pair in (a b . c)".
5_2.mo:Expected error in mat list-head: "list-head: (a b c . d) is not a proper list". 5_2.mo:Expected error in mat list-head: "list-head: index 4 reaches a non-pair in (a b c . d)".
5_2.mo:Expected error in mat list-head: "list-head: (a b . c) is not a proper list". 5_2.mo:Expected error in mat list-head: "list-head: index 10000 reaches a non-pair in (a b . c)".
5_2.mo:Expected error in mat list-head: "list-head: index 4 is out of range for list (a b c)". 5_2.mo:Expected error in mat list-head: "list-head: index 4 is out of range for list (a b c)".
5_2.mo:Expected error in mat list-head: "list-head: index 5 is out of range for list (a b c)". 5_2.mo:Expected error in mat list-head: "list-head: index 5 is out of range for list (a b c)".
5_2.mo:Expected error in mat list-head: "list-head: index 5 is out of range for list (a b c d)". 5_2.mo:Expected error in mat list-head: "list-head: index 5 is out of range for list (a b c d)".

View File

@ -80,6 +80,9 @@
(define index-range-error (define index-range-error
(lambda (who ls n) (lambda (who ls n)
($oops who "index ~s is out of range for list ~s" n ls))) ($oops who "index ~s is out of range for list ~s" n ls)))
(define index-pair-error
(lambda (who ls n)
($oops who "index ~s reaches a non-pair in ~s" n ls)))
(define index-type-error (define index-type-error
(lambda (who n) (lambda (who n)
($oops who "index ~s is not an exact nonnegative integer" n))) ($oops who "index ~s is not an exact nonnegative integer" n)))
@ -87,7 +90,7 @@
(lambda (who tail ls n) (lambda (who tail ls n)
(if (null? tail) (if (null? tail)
(index-range-error who ls n) (index-range-error who ls n)
(improper-list-error who ls)))) (index-pair-error who ls n))))
(define list-length (define list-length
(lambda (ls who) (lambda (ls who)
(let loop ([hare ls] [i 0]) (let loop ([hare ls] [i 0])

View File

@ -97,6 +97,18 @@
=> (lambda (ctc) => (lambda (ctc)
(format-error-values (string-append "contract violation\n expected: " ctc "\n given: ~s") (format-error-values (string-append "contract violation\n expected: " ctc "\n given: ~s")
irritants))] irritants))]
[(and (or (eq? who 'list-ref) (eq? who 'list-tail))
(equal? str "index ~s is out of range for list ~s"))
(values (string-append "index too large for list\n"
" index: ~s\n"
" in: ~s")
irritants)]
[(and (or (eq? who 'list-ref) (eq? who 'list-tail))
(equal? str "index ~s reaches a non-pair in ~s"))
(values (string-append "index reaches a non-pair\n"
" index: ~s\n"
" in: ~s")
irritants)]
[(equal? str "~s is not a valid index for ~s") [(equal? str "~s is not a valid index for ~s")
(cond (cond
[(exact-nonnegative-integer? (car irritants)) [(exact-nonnegative-integer? (car irritants))