diff --git a/pkgs/racket-pkgs/racket-doc/scribblings/reference/namespaces.scrbl b/pkgs/racket-pkgs/racket-doc/scribblings/reference/namespaces.scrbl index 22ea7c2d14..05d05c0c11 100644 --- a/pkgs/racket-pkgs/racket-doc/scribblings/reference/namespaces.scrbl +++ b/pkgs/racket-pkgs/racket-doc/scribblings/reference/namespaces.scrbl @@ -309,7 +309,10 @@ Returns the @tech{module registry} of the given namespace. This value is useful only for identification via @racket[eq?].} -@defproc[(module->namespace [modname module-path?]) namespace?]{ +@defproc[(module->namespace [mod (or/c module-path? + resolved-module-path? + module-path-index?)]) + namespace?]{ Returns a namespace that corresponds to the body of an instantiated module in the current namespace's @tech{module registry} and in the diff --git a/racket/src/racket/src/module.c b/racket/src/racket/src/module.c index 6da109787d..537c652654 100644 --- a/racket/src/racket/src/module.c +++ b/racket/src/racket/src/module.c @@ -3121,7 +3121,14 @@ Scheme_Object *scheme_module_to_namespace(Scheme_Object *name, Scheme_Env *env) Scheme_Env *menv; Scheme_Object *modchain; - name = scheme_module_resolve(scheme_make_modidx(name, scheme_false, scheme_false), 1); + if (SCHEME_MODNAMEP(name)) { + ; + } else if (SAME_TYPE(SCHEME_TYPE(name), scheme_module_index_type)) { + name = scheme_module_resolve(name, 1); + } else { + /* name is path or module-path */ + name = scheme_module_resolve(scheme_make_modidx(name, scheme_false, scheme_false), 1); + } menv = get_special_modenv(name); if (!menv) { @@ -3163,8 +3170,11 @@ static Scheme_Object *module_to_namespace(int argc, Scheme_Object *argv[]) env = scheme_get_env(NULL); - if (!scheme_is_module_path(argv[0])) - scheme_wrong_contract("module->namespace", "module-path?", 0, argc, argv); + if (!SCHEME_PATHP(argv[0]) + && !SCHEME_MODNAMEP(argv[0]) + && !SAME_TYPE(SCHEME_TYPE(argv[0]), scheme_module_index_type) + && !scheme_is_module_path(argv[0])) + scheme_wrong_contract("module->namespace", "(or/c module-path? module-path-index? resolved-module-path?)", 0, argc, argv); return scheme_module_to_namespace(argv[0], env); }