catch module-not-available mimatches earlier

This commit is contained in:
Matthew Flatt 2013-02-08 17:31:07 -06:00
parent 689b62a7a3
commit dd50ac8652
2 changed files with 36 additions and 3 deletions

View File

@ -949,6 +949,22 @@
(req (only-in data/queue enqueue!))))
(expand-syntax (expand src)))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; catch errors due to a module that is not available
(module avail-z racket/base
(provide foo)
(define-syntax-rule (foo x) x))
(module avail-y racket/base
(require 'avail-z)
(eval #'(foo 10)))
(err/rt-test (dynamic-require ''avail-y #f)
(lambda (exn) (and (exn? exn)
(regexp-match? #rx"module that is not available"
(exn-message exn)))))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -4278,7 +4278,7 @@ static void check_certified(Scheme_Object *stx,
symbol = stx;
stx = NULL;
}
scheme_wrong_syntax("compile", stx, symbol,
scheme_wrong_syntax(scheme_compile_stx_string, stx, symbol,
"access disallowed by code inspector to %s %s from module: %D",
prot ? "protected" : "unexported",
var ? "variable" : "syntax",
@ -4617,6 +4617,23 @@ Scheme_Object *scheme_module_syntax(Scheme_Object *modname, Scheme_Env *env,
if (!menv)
return NULL;
if (menv->module
&& menv->running
&& ((mod_phase+1) < menv->module->num_phases)
&& !menv->running[mod_phase+1]) {
scheme_wrong_syntax(scheme_compile_stx_string, NULL, name,
"module mismatch;\n"
" attempted to use a module that is not available\n"
" possible cause:\n"
" using (dynamic-require .... #f)\n"
" but need (dynamic-require .... 0)\n"
" module: %D\n"
" phase: %d",
menv->module->modsrc,
mod_phase);
return NULL;
}
for (i = 0; i < mod_phase; i++) {
scheme_prepare_exp_env(menv);
menv = menv->exp_env;
@ -5777,8 +5794,8 @@ Scheme_Env *scheme_primitive_module(Scheme_Object *name, Scheme_Env *for_env)
scheme_hash_set(for_env->module_registry->loaded, m->modname, (Scheme_Object *)m);
running = scheme_malloc_atomic(2);
running[0] = 0;
running[1] = 0;
running[0] = 1;
running[1] = 1;
env->running = running;
return env;