fix problem with lifted bindings and the top level

Repair a mismatch between `syntax-local-lift-expression` and the
way that `compile` tries to avoid creating bindings while
compiling a top-level `define` form.

Closes #1284 and #1282
This commit is contained in:
Matthew Flatt 2016-03-26 15:59:12 -06:00
parent f7182e7a5c
commit 9a3e16edff
2 changed files with 25 additions and 0 deletions

View File

@ -1564,6 +1564,19 @@
(regexp-match? #rx"cannot use identifier tainted by macro transformation"
(exn-message exn))))
;; ----------------------------------------
;; Check that lifting works right at the top level:
(module macro-that-introduces-a-lifted-one racket
(define-syntax (m stx)
(syntax-local-lift-expression #'1))
(m))
(dynamic-require ''macro-that-introduces-a-lifted-one #f)
(test 1 values (parameterize ([current-namespace
(module->namespace ''macro-that-introduces-a-lifted-one)])
(eval '(values m))))
;; ----------------------------------------
(report-errs)

View File

@ -2088,6 +2088,18 @@ scheme_do_local_lift_expr(const char *who, int stx_pos, int argc, Scheme_Object
if (env->genv->stx_context)
id = scheme_stx_introduce_to_module_context(id, env->genv->stx_context);
if (env->flags & SCHEME_TMP_TL_BIND_FRAME) {
/* When the lifetd definition is compiled, `tmp_bind_scope` will
be added to the defined name so that a fresh binding is not
created. We have added a fresh scope that would keep it
distinct, anyway, but add the tmp scope here to keep the
definition and reference in sync. */
if (!env->genv->tmp_bind_scope) {
id_sym = scheme_new_scope(SCHEME_STX_MODULE_SCOPE);
env->genv->tmp_bind_scope = id_sym;
}
id = scheme_stx_add_scope(id, env->genv->tmp_bind_scope, scheme_env_phase(env->genv));
}
rev_ids = scheme_make_pair(id, rev_ids);
}