From f4ccd0fdc6064d376fde1d8fbb101b58ce95180c Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Wed, 28 Apr 2021 07:11:00 -0600 Subject: [PATCH] expander: correct some namespace-mismatch error formats Related to #1352 --- racket/src/bc/src/startup.inc | 29 +++++++++------ racket/src/cs/schemified/expander.scm | 36 ++++++++++--------- .../src/expander/expand/binding-to-module.rkt | 21 +++++------ racket/src/expander/namespace/module.rkt | 9 ++++- 4 files changed, 58 insertions(+), 37 deletions(-) diff --git a/racket/src/bc/src/startup.inc b/racket/src/bc/src/startup.inc index bf36456a4f..dc998f36fc 100644 --- a/racket/src/bc/src/startup.inc +++ b/racket/src/bc/src/startup.inc @@ -14370,7 +14370,15 @@ static const char *startup_source = "(if or-part_1" " or-part_1" "(if complain-on-failure?_0" -" (error \"no module instance found:\" name_0 0-phase_0)" +"(error" +" 'require" +"(string-append" +" \"namespace mismatch;\\n\"" +" \" reference to a module that is not instantiated\\n\"" +" \" module: ~a\\n\"" +" \" phase: ~a\")" +" name_0" +" 0-phase_0)" " #f)))))))" "(if(if mi_0 check-available-at-phase-level_0 #f)" "(check-availablilty mi_0 check-available-at-phase-level_0 unavailable-callback_0)" @@ -15460,17 +15468,18 @@ static const char *startup_source = "(if mi_0" "(void)" "(let-values()" -"(error" -" 'expand" +"(raise-syntax-error$1" +" #f" +"(format" "(string-append" -" \"namespace mismatch; cannot locate module instance\\n\"" -" \" module: ~s\\n\"" -" \" use phase: ~a\\n\"" -" \" definition phase: ~a\\n\"" -" \" for identifier: ~s\")" -"(module-binding-module b_0)" +" \"namespace mismatch;\\n\"" +" \" cannot locate module instance\\n\"" +" \" module: ~a\\n\"" +" \" use phase: ~a\\n\"" +" \" definition phase: ~a\")" +"(1/module-path-index-resolve(module-binding-module b_0))" " phase_0" -"(module-binding-phase b_0)" +"(module-binding-phase b_0))" " id_0)))" " mi_0))))))" "(define-values" diff --git a/racket/src/cs/schemified/expander.scm b/racket/src/cs/schemified/expander.scm index c078e38528..163da0815b 100644 --- a/racket/src/cs/schemified/expander.scm +++ b/racket/src/cs/schemified/expander.scm @@ -17294,7 +17294,12 @@ or-part_2 (if complain-on-failure?55_0 (error - "no module instance found:" + 'require + (string-append + "namespace mismatch;\n" + " reference to a module that is not instantiated\n" + " module: ~a\n" + " phase: ~a") name62_0 0-phase63_0) #f)))))))) @@ -18366,21 +18371,20 @@ (void)) (if mi_0 (void) - (let ((app_0 - (string-append - "namespace mismatch; cannot locate module instance\n" - " module: ~s\n" - " use phase: ~a\n" - " definition phase: ~a\n" - " for identifier: ~s"))) - (let ((app_1 (module-binding-module b_0))) - (error - 'expand - app_0 - app_1 - phase_0 - (module-binding-phase b_0) - id_0)))) + (raise-syntax-error$1 + #f + (let ((app_0 + (string-append + "namespace mismatch;\n" + " cannot locate module instance\n" + " module: ~a\n" + " use phase: ~a\n" + " definition phase: ~a"))) + (let ((app_1 + (1/module-path-index-resolve + (module-binding-module b_0)))) + (format app_0 app_1 phase_0 (module-binding-phase b_0)))) + id_0)) mi_0))))) (define check-access (lambda (b_0 mi_0 id_0 in-s_0 what_0) diff --git a/racket/src/expander/expand/binding-to-module.rkt b/racket/src/expander/expand/binding-to-module.rkt index d2a42241be..3e7f4ef73b 100644 --- a/racket/src/expander/expand/binding-to-module.rkt +++ b/racket/src/expander/expand/binding-to-module.rkt @@ -30,14 +30,15 @@ (phase+ at-phase (module-binding-phase b))) id)) (unless mi - (error 'expand - (string-append "namespace mismatch; cannot locate module instance\n" - " module: ~s\n" - " use phase: ~a\n" - " definition phase: ~a\n" - " for identifier: ~s") - (module-binding-module b) - phase - (module-binding-phase b) - id)) + (raise-syntax-error + #f + (format (string-append "namespace mismatch;\n" + " cannot locate module instance\n" + " module: ~a\n" + " use phase: ~a\n" + " definition phase: ~a") + (module-path-index-resolve (module-binding-module b)) + phase + (module-binding-phase b)) + id)) mi) diff --git a/racket/src/expander/namespace/module.rkt b/racket/src/expander/namespace/module.rkt index b19273e876..658c5c7531 100644 --- a/racket/src/expander/namespace/module.rkt +++ b/racket/src/expander/namespace/module.rkt @@ -270,7 +270,14 @@ (let ([c-ns (or (namespace-root-namespace ns) ns)]) (hash-ref (namespace-module-instances c-ns) name #f)) (and complain-on-failure? - (error "no module instance found:" name 0-phase)))) + (error 'require + (string-append + "namespace mismatch;\n" + " reference to a module that is not instantiated\n" + " module: ~a\n" + " phase: ~a") + name + 0-phase)))) (if (and mi check-available-at-phase-level) (check-availablilty mi check-available-at-phase-level unavailable-callback) mi))