From a1f8908a2911a449d2b31bd6b068f74307b2d21a Mon Sep 17 00:00:00 2001 From: Alex Knauth Date: Thu, 7 Jul 2016 12:16:15 -0400 Subject: [PATCH] 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 --- .../typed-racket/private/type-contract.rkt | 5 ++--- typed-racket-test/fail/sandboxed-unsafe-ops.rkt | 3 ++- typed-racket-test/succeed/cast-mod.rkt | 12 ++++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/typed-racket-lib/typed-racket/private/type-contract.rkt b/typed-racket-lib/typed-racket/private/type-contract.rkt index f9ebf5a0..92eaeb4d 100644 --- a/typed-racket-lib/typed-racket/private/type-contract.rkt +++ b/typed-racket-lib/typed-racket/private/type-contract.rkt @@ -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) diff --git a/typed-racket-test/fail/sandboxed-unsafe-ops.rkt b/typed-racket-test/fail/sandboxed-unsafe-ops.rkt index e0919167..5641a59f 100644 --- a/typed-racket-test/fail/sandboxed-unsafe-ops.rkt +++ b/typed-racket-test/fail/sandboxed-unsafe-ops.rkt @@ -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)) diff --git a/typed-racket-test/succeed/cast-mod.rkt b/typed-racket-test/succeed/cast-mod.rkt index a3f8d173..0a101053 100644 --- a/typed-racket-test/succeed/cast-mod.rkt +++ b/typed-racket-test/succeed/cast-mod.rkt @@ -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")))) +