Skip to content

Commit e793fbc

Browse files
authored
Fix lookup for methods defined with eval on one line (#116)
1 parent bcbd8ed commit e793fbc

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/CodeTracking.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ function definition(::Type{String}, method::Method)
259259
lineindex = lastindex(linestarts)
260260
linestop = max(0, lineindex - 20)
261261
while !is_func_expr(ex, method) && lineindex > linestop
262+
if ex.head == :call && length(ex.args) > 1 && first(ex.args) == :eval && last(ex.args).head == :quote && length(last(ex.args).args) > 0
263+
actual_ex = first(last(ex.args).args)
264+
if is_func_expr(actual_ex, method)
265+
return clean_source(string(actual_ex)), line
266+
end
267+
end
262268
istart = linestarts[lineindex]
263269
try
264270
ex, iend = Meta.parse(src, istart)

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
250250
d = IdDict{Union{String,Symbol},Union{Function,Vector{Function}}}()
251251
CodeTracking.invoked_setindex!(d, sin, "sin")
252252
@test CodeTracking.invoked_get!(Vector{Function}, d, :cos) isa Vector{Function}
253+
254+
# Issue 115, Cthulhu issue 474
255+
m = @which NamedTuple{(),Tuple{}}(())
256+
src, line = definition(String, m)
257+
@test occursin("NamedTuple{names, T}(args::T) where {names, T <: Tuple}", src)
258+
@test line == m.line
253259
end
254260

255261
@testset "With Revise" begin

0 commit comments

Comments
 (0)