fix seg fault when using in-X-set sequence constructor with wrong kind of set; closes #2765

This commit is contained in:
Stephen Chang 2019-07-26 12:59:20 -04:00
parent 0e2d97b1e4
commit 69d748a95e
2 changed files with 22 additions and 3 deletions

View File

@ -776,6 +776,18 @@
(err/rt-test (for/sum ([x (in-weak-set '(1 2))]) x)
exn:fail:contract?
#rx"not a hash set")
(err/rt-test (for/sum ([x (in-weak-set (set 1 2))]) x)
exn:fail:contract?
#rx"wrong kind of hash set")
(err/rt-test (for/sum ([x (in-mutable-set (set 1 2))]) x)
exn:fail:contract?
#rx"wrong kind of hash set")
(err/rt-test (for/sum ([x (in-immutable-set (mutable-set 1 2))]) x)
exn:fail:contract?
#rx"wrong kind of hash set")
(err/rt-test (for/sum ([x (in-immutable-set (weak-set 1 2))]) x)
exn:fail:contract?
#rx"wrong kind of hash set")
(test 10 'in-hash-set (for/sum ([x (in-immutable-set (set 1 2 3 4))]) x))
(test 10 'in-hash-set (for/sum ([x (in-mutable-set (mutable-set 1 2 3 4))]) x))
(test 10 'in-hash-set (for/sum ([x (in-weak-set (weak-set 1 2 3 4))]) x))

View File

@ -611,7 +611,7 @@
(:do-in
;;outer bindings
([(HT fn) (let ([xs set-expr])
(if (custom-set? xs)
(if (and (custom-set? xs) (-test? xs))
(values
(custom-set-table xs)
(if (custom-set-spec xs)
@ -619,8 +619,15 @@
(lambda (x) x)))
(values #f #f)))])
;; outer check
(unless (and HT (-test? HT))
(custom-in-set/checked set-expr))
(unless HT
(define s set-expr)
(if (custom-set? s)
(raise (exn:fail:contract
(format "wrong kind of hash set, expected ~a, got: ~a\n" 'SETTYPE s)
(current-continuation-marks)))
(raise (exn:fail:contract
(format "not a hash set: ~a" s)
(current-continuation-marks)))))
;; loop bindings
([i (-first HT)])
;; pos check