diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/private/with-types.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/private/with-types.rkt index 8d898d2e..33ada5de 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/private/with-types.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/private/with-types.rkt @@ -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] diff --git a/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/fail/with-type-unregister.rkt b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/fail/with-type-unregister.rkt new file mode 100644 index 00000000..a65a7077 --- /dev/null +++ b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/fail/with-type-unregister.rkt @@ -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")) diff --git a/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/succeed/with-type-typed-context-flag.rkt b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/succeed/with-type-typed-context-flag.rkt new file mode 100644 index 00000000..1c3d3e48 --- /dev/null +++ b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/succeed/with-type-typed-context-flag.rkt @@ -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))