make variable-reference->namespace enable top-level mode

The namespace returned by `variable-reference->namespace` (or
`namespace-anchor->namespace`) may be used via `eval` to define new
bindings, so enable top-level binding support for the namespace.
This commit is contained in:
Matthew Flatt 2016-07-14 15:02:46 -06:00
parent 19707a54be
commit d1c2daf15b
2 changed files with 16 additions and 0 deletions

View File

@ -1780,6 +1780,21 @@ case of module-leve bindings; it doesn't cover local bindings.
(test 5 dynamic-require ''module-that-exports-phase-2-x-at-phase-0 'x)
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Check that
;; `namespace-anchor->namespace` internally enables top-level mode for
;; binding handling:
;; Example from Alex Knauth:
(module module-that-uses-eval-to-define-a-macro-in-its-own-namespace racket/base
(require (for-syntax racket/base))
(define-namespace-anchor a)
(define ns (namespace-anchor->namespace a))
(eval '(define-syntax x (λ (stx) #'333)) ns)
(define result (eval 'x ns))
(provide result))
(test 333 dynamic-require ''module-that-uses-eval-to-define-a-macro-in-its-own-namespace 'result)
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(report-errs)

View File

@ -2120,6 +2120,7 @@ static Scheme_Object *do_variable_namespace(const char *who, int tl, int argc, S
/* return env directly; need to set up */
if (!env->phase && env->module)
scheme_prep_namespace_rename(env);
env->interactive_bindings = 1;
} else {
/* new namespace: */
Scheme_Env *new_env;