Fix with-type when used at the top-level

In some situations, with-type would fail to clean up its
state before reporting an error at the top-level.

original commit: 591147dd028d4586e4346d83706d38454f043172
This commit is contained in:
Asumu Takikawa 2014-11-21 02:06:00 -05:00
parent a27553b1f6
commit 569b55bf69
3 changed files with 35 additions and 1 deletions

View File

@ -89,11 +89,13 @@
;; to TR
(tc-toplevel-form lifted-definitions)
(tc-expr/check expanded-body (if expr? region-tc-result (ret ex-types))))
(report-all-errors)
(set-box! typed-context? old-context)
;; then clear the new entries from the env ht
(for ([i (in-syntax fvids)])
(unregister-type i))
;; report errors after setting the typed-context? flag and unregistering
;; types to ensure that the state is cleaned up properly in the REPL
(report-all-errors)
(with-syntax ([(fv.id ...) fvids]
[(cnt ...) fv-ctc-ids]
[(ex-id ...) exids]

View File

@ -0,0 +1,18 @@
#;
(exn-pred #rx"missing a type annotation")
#lang racket/load
(require (only-in typed/racket with-type String)
unstable/macro-testing)
;; Ensure that types are unregistered in the type environment for free
;; variables for a `with-type` at the top-level
(define x "foo")
(with-handlers ([exn:fail:syntax? void])
(convert-compile-time-error
(with-type #:result String #:freevars ([x String]) (string-append x 3))))
;; should error because `x` shouldn't have a type
(with-type #:result String (string-append x "bar"))

View File

@ -0,0 +1,14 @@
#lang racket/load
(require (only-in typed/racket with-type)
unstable/macro-testing)
;; Test that the typed-context? flag is properly reset
(with-handlers ([exn:fail:syntax? void])
(convert-compile-time-error
(with-type [] (+ 1 "foo"))))
;; this should succeed instead of an error due to the typed-context?
;; flag being set to #t
(with-type [] (+ 1 3))