check for free-vars in types of casted-exprs (#384)

This commit is contained in:
Alex Knauth 2016-07-07 14:45:07 -04:00 committed by GitHub
parent 39d6a6047a
commit e3f56c8a25
2 changed files with 15 additions and 0 deletions

View File

@ -343,13 +343,17 @@
(define existing-ty-ctc (syntax-local-lift-expression
(make-contract-def-rhs/from-typed existing-ty-id #f #f)))
(define (store-existing-type existing-type)
(check-no-free-vars existing-type #'v)
(cast-table-set! existing-ty-id (datum->syntax #f existing-type #'v)))
(define (check-valid-type _)
(define type (parse-type #'ty))
(check-no-free-vars type #'ty))
(define (check-no-free-vars type stx)
(define vars (fv type))
;; If there was an error don't create another one
(unless (or (Error? type) (null? vars))
(tc-error/delayed
#:stx stx
"Type ~a could not be converted to a contract because it contains free variables."
type)))
#`(#,(external-check-property #'#%expression check-valid-type)

View File

@ -0,0 +1,11 @@
#;
(exn-pred exn:fail:syntax?
#rx"Type \\(List X\\) could not be converted to a contract"
#rx"contains free variables"
#rx"10.8")
#lang typed/racket
(: f : (All (X) (-> X X)))
(define (f x)
(cast (list x) Any)
x)