typed-racket/typed-racket-test/succeed/pr226-variation-1.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

19 lines
462 B
Racket

#lang typed/racket
;; Struct predicates should not be wrapped in a contract
;; when they cross a typed/untyped boundary.
;; We know they're safe! Don't suffer the indirection cost.
(module untyped racket
(struct s ())
(provide (struct-out s)))
(require/typed 'untyped
[#:struct s ()])
(require/typed racket/contract/base
[has-contract? (-> Any Boolean)])
(when (has-contract? s?)
(error 'pr226 "safe struct predicate was wrapped in a contract"))