Skip to content

Commit

Permalink
Fix adding docstring to module with none (#585)
Browse files Browse the repository at this point in the history
Workaround for julia#38819
Fixes #583
  • Loading branch information
timholy authored Dec 10, 2020
1 parent 1dd0a70 commit 40ce40c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lowered.jl
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,10 @@ function methods_by_execution!(@nospecialize(recurse), methodinfo, docexprs, fra
dmod = tmpvar
end
end
# Workaround for julia#38819 on older Julia versions
if !isdefined(dmod, Base.Docs.META)
Base.Docs.initmeta(dmod)
end
m = get!(Base.Docs.meta(dmod), b, Base.Docs.MultiDoc())::Base.Docs.MultiDoc
if haskey(m.docs, sig)
currentstr = m.docs[sig]::Base.Docs.DocStr
Expand Down
36 changes: 36 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,7 @@ end
println(io, """
module ChangeDocstring
"f" f() = 1
g() = 1
end
""")
end
Expand All @@ -1172,17 +1173,23 @@ end
@test ChangeDocstring.f() == 1
ds = @doc(ChangeDocstring.f)
@test get_docstring(ds) == "f"
@test ChangeDocstring.g() == 1
ds = @doc(ChangeDocstring.g)
@test get_docstring(ds) == "No documentation found."
# Ordinary route
open(joinpath(dn, "ChangeDocstring.jl"), "w") do io
println(io, """
module ChangeDocstring
"h" f() = 1
"g" g() = 1
end
""")
end
yry()
ds = @doc(ChangeDocstring.f)
@test get_docstring(ds) == "h"
ds = @doc(ChangeDocstring.g)
@test get_docstring(ds) == "g"

# Now manually change the docstring
ex = quote "g" f() = 1 end
Expand All @@ -1196,6 +1203,35 @@ end
@test get_docstring(ds) == "g"

rm_precompile("ChangeDocstring")

# Test for #583
dn = joinpath(testdir, "FirstDocstring", "src")
mkpath(dn)
open(joinpath(dn, "FirstDocstring.jl"), "w") do io
println(io, """
module FirstDocstring
g() = 1
end
""")
end
sleep(mtimedelay)
@eval using FirstDocstring
sleep(mtimedelay)
@test FirstDocstring.g() == 1
ds = @doc(FirstDocstring.g)
@test get_docstring(ds) == "No documentation found."
open(joinpath(dn, "FirstDocstring.jl"), "w") do io
println(io, """
module FirstDocstring
"g" g() = 1
end
""")
end
yry()
ds = @doc(FirstDocstring.g)
@test get_docstring(ds) == "g"

rm_precompile("FirstDocstring")
pop!(LOAD_PATH)
end

Expand Down

0 comments on commit 40ce40c

Please sign in to comment.