cs: fix {{,fx,fl}vector,string,bytes}-ref error-message rewrite

Fix the ending index, since it's inclusive.

Thanks to Matthias for the report.
This commit is contained in:
Matthew Flatt 2020-11-13 17:26:52 -07:00
parent 78b09313a0
commit b37cc53b70
5 changed files with 16 additions and 2 deletions

View File

@ -822,6 +822,7 @@
(err/rt-test (string-set! hello-string 5 #\a) exn:application:mismatch?) (err/rt-test (string-set! hello-string 5 #\a) exn:application:mismatch?)
(err/rt-test (string-set! hello-string -1 #\a)) (err/rt-test (string-set! hello-string -1 #\a))
(err/rt-test (string-set! hello-string (expt 2 100) #\a) exn:application:mismatch?) (err/rt-test (string-set! hello-string (expt 2 100) #\a) exn:application:mismatch?)
(err/rt-test (string-set! (string #\4 #\5 #\6) 4 #\?) exn:fail:contract? #rx"[[]0, 2[]]")
(test "abc" string #\a #\b #\c) (test "abc" string #\a #\b #\c)
(test "" string) (test "" string)
(err/rt-test (string #\a 1)) (err/rt-test (string #\a 1))
@ -841,6 +842,7 @@
(err/rt-test (string-ref "" 0) exn:application:mismatch?) (err/rt-test (string-ref "" 0) exn:application:mismatch?)
(err/rt-test (string-ref "" (expt 2 100)) exn:application:mismatch?) (err/rt-test (string-ref "" (expt 2 100)) exn:application:mismatch?)
(err/rt-test (string-ref "apple" -1)) (err/rt-test (string-ref "apple" -1))
(err/rt-test (string-ref "456" 4) exn:fail:contract? #rx"[[]0, 2[]]")
(test "" substring "ab" 0 0) (test "" substring "ab" 0 0)
(test "" substring "ab" 1 1) (test "" substring "ab" 1 1)
(test "" substring "ab" 2 2) (test "" substring "ab" 2 2)
@ -1148,6 +1150,7 @@
(err/rt-test (bytes-set! hello-bytes 5 97) exn:application:mismatch?) (err/rt-test (bytes-set! hello-bytes 5 97) exn:application:mismatch?)
(err/rt-test (bytes-set! hello-bytes -1 97)) (err/rt-test (bytes-set! hello-bytes -1 97))
(err/rt-test (bytes-set! hello-bytes (expt 2 100) 97) exn:application:mismatch?) (err/rt-test (bytes-set! hello-bytes (expt 2 100) 97) exn:application:mismatch?)
(err/rt-test (bytes-set! (bytes 4 5 6) 4 0) exn:fail:contract? #rx"[[]0, 2[]]")
(test #"abc" bytes 97 98 99) (test #"abc" bytes 97 98 99)
(test #"" bytes) (test #"" bytes)
(err/rt-test (bytes #\a 1)) (err/rt-test (bytes #\a 1))
@ -1167,6 +1170,7 @@
(err/rt-test (bytes-ref #"" 0) exn:application:mismatch?) (err/rt-test (bytes-ref #"" 0) exn:application:mismatch?)
(err/rt-test (bytes-ref #"" (expt 2 100)) exn:application:mismatch?) (err/rt-test (bytes-ref #"" (expt 2 100)) exn:application:mismatch?)
(err/rt-test (bytes-ref #"apple" -1)) (err/rt-test (bytes-ref #"apple" -1))
(err/rt-test (bytes-ref (bytes 4 5 6) 4) exn:fail:contract? #rx"[[]0, 2[]]")
(test #"" subbytes #"ab" 0 0) (test #"" subbytes #"ab" 0 0)
(test #"" subbytes #"ab" 1 1) (test #"" subbytes #"ab" 1 1)
(test #"" subbytes #"ab" 2 2) (test #"" subbytes #"ab" 2 2)

View File

@ -167,6 +167,9 @@
;; ---------------------------------------- ;; ----------------------------------------
(err/rt-test (fxvector-ref (fxvector 4 5 6) 4) exn:fail:contract? #rx"[[]0, 2[]]")
(err/rt-test (fxvector-set! (fxvector 4 5 6) 4 0) exn:fail:contract? #rx"[[]0, 2[]]")
;; in-fxvector tests. ;; in-fxvector tests.
(let ((flv (fxvector 1 2 3))) (let ((flv (fxvector 1 2 3)))
(let ((flv-seq (in-fxvector flv))) (let ((flv-seq (in-fxvector flv)))

View File

@ -47,6 +47,9 @@
(test #t same-results (list-ref line 0) (list-ref line 1) (list i k j)) (test #t same-results (list-ref line 0) (list-ref line 1) (list i k j))
(test #t same-results (list-ref line 0) (list-ref line 1) (cons i more-flonums)))))) (test #t same-results (list-ref line 0) (list-ref line 1) (cons i more-flonums))))))
(err/rt-test (flvector-ref (flvector 4.0 5.0 6.0) 4) exn:fail:contract? #rx"[[]0, 2[]]")
(err/rt-test (flvector-set! (flvector 4.0 5.0 6.0) 4 0.0) exn:fail:contract? #rx"[[]0, 2[]]")
(define (flonum-close? fl1 fl2) (define (flonum-close? fl1 fl2)
(<= (flabs (fl- fl1 fl2)) (<= (flabs (fl- fl1 fl2))
1e-8)) 1e-8))

View File

@ -24,6 +24,7 @@
(err/rt-test (vector-ref #(4 5 6) -1)) (err/rt-test (vector-ref #(4 5 6) -1))
(err/rt-test (vector-ref #(4 5 6) 2.0)) (err/rt-test (vector-ref #(4 5 6) 2.0))
(err/rt-test (vector-ref #(4 5 6) "2")) (err/rt-test (vector-ref #(4 5 6) "2"))
(err/rt-test (vector-ref #(4 5 6) 4) exn:fail:contract? #rx"[[]0, 2[]]")
(test '#(0 ("Sue" "Sue") "Anna") 'vector-set! (test '#(0 ("Sue" "Sue") "Anna") 'vector-set!
(let ((vec (vector 0 '(2 2 2 2) "Anna"))) (let ((vec (vector 0 '(2 2 2 2) "Anna")))
(vector-set! vec 1 '("Sue" "Sue")) (vector-set! vec 1 '("Sue" "Sue"))
@ -54,6 +55,7 @@
(err/rt-test (vector-set! #(1 2 3) (expt 2 100) 'x) exn:application:mismatch?) (err/rt-test (vector-set! #(1 2 3) (expt 2 100) 'x) exn:application:mismatch?)
(err/rt-test (vector-set! '(1 2 3) 2 'x)) (err/rt-test (vector-set! '(1 2 3) 2 'x))
(err/rt-test (vector-set! #(1 2 3) "2" 'x)) (err/rt-test (vector-set! #(1 2 3) "2" 'x))
(err/rt-test (vector-set! (vector 4 5 6) 4 0) exn:fail:contract? #rx"[[]0, 2[]]")
(define v (vector 1 2 3)) (define v (vector 1 2 3))
(vector-fill! v 0) (vector-fill! v 0)
(test (quote #(0 0 0)) 'vector-fill! v) (test (quote #(0 0 0)) 'vector-fill! v)
@ -146,7 +148,8 @@
(let ([v (vector 1 2 3)]) (let ([v (vector 1 2 3)])
(test #f eq? v (vector-copy v)))) (test #f eq? v (vector-copy v))))
(err/rt-test (vector-copy #(4 5 6) 4) exn:fail:contract? #rx"[[]0, 3[]]")
(err/rt-test (vector-copy #(4 5 6) 1 4) exn:fail:contract? #rx"[[]0, 3[]]")
;; ---------- vector-arg{min,max} ---------- ;; ---------- vector-arg{min,max} ----------

View File

@ -92,10 +92,11 @@
[(bytes? v) (values "byte string" (bytes-length v))] [(bytes? v) (values "byte string" (bytes-length v))]
[(string? v) (values "string" (string-length v))] [(string? v) (values "string" (string-length v))]
[(fxvector? v) (values "fxvector" (fxvector-length v))] [(fxvector? v) (values "fxvector" (fxvector-length v))]
[(flvector? v) (values "flvector" (flvector-length v))]
[else (values "value" #f)]))]) [else (values "value" #f)]))])
(format-error-values (string-append "index is out of range\n" (format-error-values (string-append "index is out of range\n"
" index: ~s\n" " index: ~s\n"
" valid range: [0, " (if len (number->string len) "...") "]\n" " valid range: [0, " (if len (number->string (sub1 len)) "...") "]\n"
" " what ": ~s") " " what ": ~s")
irritants))] irritants))]
[else [else