Skip to content

Commit 8038678

Browse files
authored
Merge pull request #48 from JuliaDebug/teh/docexprs
Fix and test docstring extraction
2 parents 65f3c3d + 7d016f9 commit 8038678

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/JuliaInterpreter.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ function prepare_toplevel!(modexs, docexprs, lex::Expr, mod::Module, ex::Expr; e
455455
end
456456
push!(docexs, ex)
457457
body = ex.args[4]
458-
if isa(body, Expr)
458+
if isa(body, Expr) && body.head != :call
459459
prepare_toplevel!(modexs, docexprs, lex, mod, body; extract_docexprs=extract_docexprs, filename=filename)
460460
end
461461
else

test/toplevel.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,37 @@ end
287287
end
288288
@test LowerAnon.z == [4,7,12]
289289
end
290+
291+
@testset "Docstrings" begin
292+
ex = quote
293+
"""
294+
A docstring
295+
"""
296+
f(x) = 1
297+
298+
g(T::Type) = 1
299+
g(x) = 2
300+
301+
"""
302+
Docstring 2
303+
"""
304+
g(T::Type)
305+
306+
module Sub
307+
"""
308+
Docstring 3
309+
"""
310+
f(x) = 2
311+
end
312+
end
313+
Core.eval(Toplevel, Expr(:toplevel, ex.args...))
314+
modexs, docexprs = JuliaInterpreter.prepare_toplevel(Toplevel, ex; extract_docexprs=true)
315+
for (mod, ex) in modexs
316+
frame = JuliaInterpreter.prepare_thunk(mod, ex)
317+
while true
318+
JuliaInterpreter.through_methoddef_or_done!(stack, frame) === nothing && break
319+
end
320+
end
321+
@test length(docexprs[Toplevel]) == 2
322+
@test length(docexprs[Toplevel.Sub]) == 1
323+
end

0 commit comments

Comments
 (0)