diff --git a/pkgs/racket-test-core/tests/racket/module.rktl b/pkgs/racket-test-core/tests/racket/module.rktl index b847c08273..eec4effbd8 100644 --- a/pkgs/racket-test-core/tests/racket/module.rktl +++ b/pkgs/racket-test-core/tests/racket/module.rktl @@ -2707,6 +2707,19 @@ case of module-leve bindings; it doesn't cover local bindings. (namespace-attach-module-declaration (current-namespace) ''please-attach-me-successfully (make-base-namespace)) +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Make sure that a module with an attached instance +;; cannot be redeclared in the target namespace + +(module module-to-attach-elsewhere racket/base) +(dynamic-require ''module-to-attach-elsewhere #f) +(eval '(module module-to-attach-elsewhere racket/base)) ; to to redeclare here +(let ([ns (make-base-namespace)]) + (namespace-attach-module (current-namespace) ''module-to-attach-elsewhere ns) + (err/rt-test (eval '(module module-to-attach-elsewhere racket/base))) + (parameterize ([current-namespace ns]) + (err/rt-test (eval '(module module-to-attach-elsewhere racket/base))))) + ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Check that `local-expand` doesn't make module available in a way ;; that allows the module to import itself diff --git a/racket/src/expander/namespace/module.rkt b/racket/src/expander/namespace/module.rkt index 01454f7c9c..b19273e876 100644 --- a/racket/src/expander/namespace/module.rkt +++ b/racket/src/expander/namespace/module.rkt @@ -289,6 +289,7 @@ [declaration-inspector (module-inspector m)] [inspector (namespace-inspector existing-m-ns)])) (define mi (make-module-instance m-ns m)) + (set-module-instance-attached?! mi #t) (cond [(module-cross-phase-persistent? m) (small-hash-set! (namespace-phase-to-namespace m-ns) 0 m-ns) diff --git a/racket/src/racket/src/startup.inc b/racket/src/racket/src/startup.inc index 6ddc2f35e1..85d7467aaa 100644 --- a/racket/src/racket/src/startup.inc +++ b/racket/src/racket/src/startup.inc @@ -14275,6 +14275,8 @@ static const char *startup_source = "(namespace-module-instances the-struct_0)))" " (raise-argument-error 'struct-copy \"namespace?\" the-struct_0)))))" "(let-values(((mi_0)(make-module-instance m-ns_0 m_0)))" +"(begin" +"(set-module-instance-attached?! mi_0 #t)" "(if(module-cross-phase-persistent? m_0)" "(let-values()" "(begin" @@ -14296,7 +14298,9 @@ static const char *startup_source = "(small-hash-set!(module-instance-phase-level-to-state mi_0) 0 'started)))" "(let-values()" "(let-values((()" -"(begin(small-hash-set!(namespace-phase-to-namespace m-ns_0) 0-phase_0 m-ns_0)(values))))" +"(begin" +"(small-hash-set!(namespace-phase-to-namespace m-ns_0) 0-phase_0 m-ns_0)" +"(values))))" "(let-values((()" "(begin" "(small-hash-set!" @@ -14309,14 +14313,15 @@ static const char *startup_source = "(small-hash-set!(module-instance-phase-level-to-state mi_0) 0 'started)" "(values))))" "(let-values(((at-phase_0)" -"(let-values(((or-part_0)(hash-ref(namespace-module-instances ns_0) 0-phase_0 #f)))" +"(let-values(((or-part_0)" +"(hash-ref(namespace-module-instances ns_0) 0-phase_0 #f)))" "(if or-part_0" " or-part_0" "(let-values(((at-phase_0)(make-hasheq)))" "(begin" "(hash-set!(namespace-module-instances ns_0) 0-phase_0 at-phase_0)" " at-phase_0))))))" -"(hash-set! at-phase_0 name_0 mi_0))))))))))))" +"(hash-set! at-phase_0 name_0 mi_0)))))))))))))" "(define-values" "(namespace-create-module-instance!)" "(lambda(ns_0 name_0 0-phase_0 m_0 mpi_0)"