From 78881f1e2240ff012caf8836fc13f07d72b10e7b Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 5 May 2017 15:59:50 -0400 Subject: [PATCH] get loaddocs to give line numbers when it fails --- base/docs/Docs.jl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/base/docs/Docs.jl b/base/docs/Docs.jl index 005d4a6a9f881..53552372a265d 100644 --- a/base/docs/Docs.jl +++ b/base/docs/Docs.jl @@ -749,11 +749,21 @@ include("utils.jl") # Swap out the bootstrap macro with the real one. Core.atdoc!(docm) +macro local_hygiene(expr) + # removes `esc` Exprs relative to the module argument to expand + # and resolves everything else relative to this (Doc) module + # this allows us to get good errors and backtraces + # from calling docm (by not using macros), + # while also getting macro-expansion correct (by using the macro-expander) + return expr +end function loaddocs(docs) + unescape = GlobalRef(Docs, Symbol("@local_hygiene")) for (mod, ex, str, file, line) in docs data = Dict(:path => string(file), :linenumber => line) doc = docstr(str, data) - eval(mod, :(@doc($doc, $ex, false))) + 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) + eval(mod, Expr(:macrocall, unescape, nothing, docstring)) end empty!(docs) end