Skip to content

Commit 8ff474f

Browse files
authored
Fix pr #116 (#118)
ex doesn't have to be an expression, it can be a Symbol
1 parent c2128a2 commit 8ff474f

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/CodeTracking.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ 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
262+
if isexpr(ex, :call) && length(ex.args) > 1 && first(ex.args) == :eval && isexpr(last(ex.args), :quote) && length(last(ex.args).args) > 0
263263
actual_ex = first(last(ex.args).args)
264264
if is_func_expr(actual_ex, method)
265265
return clean_source(string(actual_ex)), line

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
262262
src, line = definition(String, m)
263263
@test occursin("NamedTuple{names, T}(args::T) where {names, T <: Tuple}", src)
264264
@test line == m.line
265+
266+
# Parsed result gives a symbol instead of expression
267+
m = @which symbol_function(1)
268+
@test_nowarn definition(String, m)
265269
end
266270

267271
@testset "With Revise" begin

test/script.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,8 @@ end
124124
struct Invert end
125125
(::Invert)(v::AbstractVector{Bool}) = (!).(v)
126126
(::Type{T})(itr) where {T<:Invert} = [!x for x in itr]
127+
128+
# USERID gets parsed into a Symbol
129+
struct symbol_struct2
130+
USERID
131+
end; '\n' ;symbol_function(x) = x

0 commit comments

Comments
 (0)