diff --git a/collects/scribblings/reference/namespaces.scrbl b/collects/scribblings/reference/namespaces.scrbl index 3642e3d78a..2c76cfdcff 100644 --- a/collects/scribblings/reference/namespaces.scrbl +++ b/collects/scribblings/reference/namespaces.scrbl @@ -413,9 +413,9 @@ result is @racket[#f].} If @racket[varref] refers to a @tech{module-level variable}, the result is a path or symbol naming the module's source (which is -typically, but not always, the same as in the resolved module path). -If the module is a submodule, the result corresponds to the enclosing -top-level module's source. +typically, but not always, the same as in the @tech{resolved module +path}). If the relevant module is a @tech{submodule}, the result +corresponds to the enclosing top-level module's source. If @racket[varref] refers to a @tech{top-level variable}, then the result is @racket[#f].} diff --git a/collects/syntax/location.rkt b/collects/syntax/location.rkt index aa139abeee..57e0cc898a 100644 --- a/collects/syntax/location.rkt +++ b/collects/syntax/location.rkt @@ -47,8 +47,16 @@ [quote-character-position source-location-position] [quote-character-span source-location-span]) +(define (variable-reference->module-source/submod vr) + (define src (variable-reference->module-source vr)) + (define rname (variable-reference->resolved-module-path vr)) + (define name (and rname (resolved-module-path-name rname))) + (if (pair? name) + (cons src (cdr name)) + src)) + (define-syntax-rule (module-source) - (variable-reference->module-source + (variable-reference->module-source/submod (#%variable-reference))) (define-for-syntax (do-quote-module stx fixup)