Skip to content

Commit 2496b4e

Browse files
committed
get loaddocs to give line numbers when it fails
1 parent 25f241c commit 2496b4e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

base/docs/Docs.jl

+11-1
Original file line numberDiff line numberDiff line change
@@ -742,11 +742,21 @@ include("utils.jl")
742742
# Swap out the bootstrap macro with the real one.
743743
Core.atdoc!(docm)
744744

745+
macro local_hygiene(expr)
746+
# removes `esc` Exprs relative to the module argument to expand
747+
# and resolves everything else relative to this (Doc) module
748+
# this allows us to get good errors and backtraces
749+
# from calling docm (by not using macros),
750+
# while also getting macro-expansion correct (by using the macro-expander)
751+
return expr
752+
end
745753
function loaddocs(docs)
754+
unescape = GlobalRef(Docs, Symbol("@local_hygiene"))
746755
for (mod, ex, str, file, line) in docs
747756
data = Dict(:path => string(file), :linenumber => line)
748757
doc = docstr(str, data)
749-
eval(mod, :(@doc($doc, $ex, false)))
758+
docstring = eval(mod, Expr(:body, Expr(:return, Expr(:call, QuoteNode(docm), QuoteNode(doc), QuoteNode(ex), false)))) # expand the real @doc macro now (using a hack because macroexpand takes current-module as an implicit argument)
759+
eval(mod, Expr(:macrocall, unescape, nothing, docstring))
750760
end
751761
empty!(docs)
752762
end

0 commit comments

Comments
 (0)