typed-racket/typed-racket-test/succeed/pr241-variation-1.rkt
Sam Tobin-Hochstadt d3fac7c24a Revise handling of #:opaque types, and Any.
Guard opaque predicates with an (-> Any Any) contract. This uses the
contract generation infrastructure to avoid wrapping struct predicates.

Also, relax `any-wrap/c` (the contract used for `Any` in positive
position) to allow opaque structures. This also requires an enumeration
of all the other kinds of values that TR understands, so that they are
not confused with opaque structures.

Joint work with @bennn.

Closes #202.
Closes #203.
Closes #241.
2015-12-30 12:33:15 -05:00

22 lines
442 B
Racket

#lang racket/base
;; #:opaque predicates should not change the type of their arguments
(module untyped racket/base
(define (bad x)
(set-box! x 5)
#t)
(provide bad))
(module typed typed/racket/base
(require/typed (submod ".." untyped)
[#:opaque T bad])
(: b (Boxof String))
(define b (box "hi"))
(with-handlers ([exn:fail:contract? (lambda (e) (void))])
(bad b)
(void))
(string-append (unbox b) ""))
(require 'typed)