Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/CodeTracking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ end

Returns the code-string for the method definition for `f` with the specified types.
"""
code_string(f, t) = definition(String, which(f, t))[1]
function code_string(f, t)
def = definition(String, which(f, t))
return def === nothing ? nothing : def[1]
end
macro code_string(ex0...)
InteractiveUtils.gen_call_with_extracted_types_and_kwargs(__module__, :code_string, ex0)
end
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
m = first(methods(getfield(mod, :eval)))
@test definition(String, m) === nothing
end

# Related to issue [#51](https://github.com/timholy/CodeTracking.jl/issues/51)
# and https://github.com/JuliaDocs/Documenter.jl/issues/1779
ex = :(f_no_linenum(::Int) = 1)
deleteat!(ex.args[2].args, 1) # delete the file & line number info
eval(ex)
@test code_string(f_no_linenum, (Int,)) === nothing
end

@testset "With Revise" begin
Expand Down