call compute-constraints instead of sc->constraints in get-max-contract-kind (#382)

* call compute-constraints instead of sc->constraints in get-max-contract-kind

* test cast on an intersection type involving Rec

* remove memory limit on sandboxed-unsafe-ops test
This commit is contained in:
Alex Knauth 2016-07-07 12:16:15 -04:00 committed by GitHub
parent 76cb6ae53d
commit a1f8908a29
3 changed files with 16 additions and 4 deletions

View File

@ -18,6 +18,7 @@
syntax/flatten-begin
(only-in (types abbrev) -Bottom -Boolean)
(static-contracts instantiate optimize structures combinators constraints)
(only-in (submod typed-racket/static-contracts/instantiate internals) compute-constraints)
;; TODO make this from contract-req
(prefix-in c: racket/contract)
(contract-req)
@ -221,9 +222,7 @@
;; recurse into a contract finding the max
;; kind (e.g. flat < chaperone < impersonator)
(define (get-max-contract-kind sc)
(define (get-restriction sc)
(sc->constraints sc get-restriction))
(kind-max-max (contract-restrict-value (get-restriction sc))))
(kind-max-max (contract-restrict-value (compute-constraints sc 'impersonator))))
;; To avoid misspellings
(define impersonator-sym 'impersonator)

View File

@ -7,7 +7,8 @@
(require racket/sandbox)
(parameterize ([sandbox-memory-limit 5000])
;; this doesn't need a memory limit
(parameterize ([sandbox-memory-limit #f])
(define eval (make-evaluator 'typed/racket))
(eval '(require typed/racket/unsafe))

View File

@ -90,3 +90,15 @@
(λ () (set-s-i! s4 "hello")))
(check-equal? (s-i s1) 42))
(test-case "cast on intersections involving recursive types"
(define-type T
(Rec T (U String (Listof T))))
(: f : (Listof T) -> Any)
(define (f x)
(if (andmap list? x)
(cast x Any)
#f))
(check-equal? (f (list "a" "b" "c")) #f)
(check-equal? (f (list (list "a") (list "b") (list "c")))
(list (list "a") (list "b") (list "c"))))