typed-racket/typed-racket-test/succeed/pr226-variation-2.rkt
ben 5d4477d08d safe & efficient (-> Any Boolean) contract
New strategy for compiling the (-> Any Boolean) type to a contract.
When possible, uses `struct-predicate-procedure?` instead of
 wrapping in `(-> any-wrap/c boolean?)`.
Makes exceptions for untyped chaperones/impersonators over struct predicates;
 those are always wrapped with `(-> any-wrap/c boolean?)`.

This change also affects (require/typed ... [#:struct ...]), but not #:opaque
2015-11-09 19:04:02 -05:00

21 lines
589 B
Racket

#lang typed/racket
;; Chaperoned struct predicates must be wrapped in a contract.
;; (Even though `struct-predicate-procedure?` will return
;; true for these values)
(module untyped racket
(struct s ())
(define s?? (chaperone-procedure s? (lambda (x) (x) x)))
;; provide enough names to trick #:struct
(provide s struct:s (rename-out [s?? s?])))
(require/typed 'untyped
[#:struct s ()])
(define (fail-if-called)
(error 'pr226 "Untyped code invoked a higher-order value passed as 'Any'"))
(with-handlers ([exn:fail:contract? (lambda (e) 'success)])
(s? fail-if-called))