
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
21 lines
589 B
Racket
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))
|