fix module->namespace problem resoring bindings

If a module has any sort of complex bindings, such as a definition of
a macor-introduced identifiers, then `module->namespace` and variants
(like `variable-reference->namespace`) need to recreate suitable
bindings. Make sure that the module-path index for recreated bindings
is the run-time one, not the compile-time one.

Closes #1584
This commit is contained in:
Matthew Flatt 2017-01-27 16:40:15 -07:00
parent 0a5c510b72
commit 03f2deeea9
2 changed files with 34 additions and 1 deletions

View File

@ -2017,6 +2017,37 @@ case of module-leve bindings; it doesn't cover local bindings.
(parameterize ([read-accept-compiled #t])
(read (open-input-bytes (get-output-bytes o)))))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Make sure that when `variable-reference->namespace`
;; reconstitutes variable mappings, that it uses the
;; run-time module path index of the module instead
;; of it's compile-time module path index
(parameterize ([current-module-declare-name
(make-resolved-module-path 'uses-own-namespace-for-eval-from-submodule)])
(eval
'(module m racket/base
(require (for-syntax racket/base))
(define (x) 1)
(define-syntax-rule (def) (define y 0))
(def)
(void
(variable-reference->namespace (#%variable-reference)))
(define (get-x)
(eval '(x) (variable-reference->namespace (#%variable-reference))))
(module* main #f
(provide v)
(define v
(parameterize ([current-namespace (variable-reference->namespace (#%variable-reference))])
(eval '(get-x))))))))
(test 1 dynamic-require '(submod 'uses-own-namespace-for-eval-from-submodule main) 'v)
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(report-errs)

View File

@ -1613,7 +1613,9 @@ void scheme_shadow(Scheme_Env *env, Scheme_Object *n, Scheme_Object *val, int as
scheme_add_module_binding(id, scheme_env_phase(env),
(env->module
? env->module->self_modidx
? (env->link_midx
? env->link_midx
: env->module->self_modidx)
: scheme_false),
((env->module && env->module->prefix)
? env->module->prefix->src_insp_desc