From 3dad358f1296f8875732e02003beacdd73aae502 Mon Sep 17 00:00:00 2001 From: Zentrik Date: Thu, 10 Aug 2023 10:22:25 +0100 Subject: [PATCH] Fix pr #116 ex doesn't have to be an expression, it can be a Symbol --- src/CodeTracking.jl | 2 +- test/runtests.jl | 4 ++++ test/script.jl | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/CodeTracking.jl b/src/CodeTracking.jl index f8564ff..f1bcea9 100644 --- a/src/CodeTracking.jl +++ b/src/CodeTracking.jl @@ -259,7 +259,7 @@ function definition(::Type{String}, method::Method) lineindex = lastindex(linestarts) linestop = max(0, lineindex - 20) while !is_func_expr(ex, method) && lineindex > linestop - if ex.head == :call && length(ex.args) > 1 && first(ex.args) == :eval && last(ex.args).head == :quote && length(last(ex.args).args) > 0 + if isexpr(ex, :call) && length(ex.args) > 1 && first(ex.args) == :eval && isexpr(last(ex.args), :quote) && length(last(ex.args).args) > 0 actual_ex = first(last(ex.args).args) if is_func_expr(actual_ex, method) return clean_source(string(actual_ex)), line diff --git a/test/runtests.jl b/test/runtests.jl index 347c3cf..84105a5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -262,6 +262,10 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j src, line = definition(String, m) @test occursin("NamedTuple{names, T}(args::T) where {names, T <: Tuple}", src) @test line == m.line + + # Parsed result gives a symbol instead of expression + m = @which symbol_function(1) + @test_nowarn definition(String, m) end @testset "With Revise" begin diff --git a/test/script.jl b/test/script.jl index dba6b0f..9d4a2ba 100644 --- a/test/script.jl +++ b/test/script.jl @@ -124,3 +124,8 @@ end struct Invert end (::Invert)(v::AbstractVector{Bool}) = (!).(v) (::Type{T})(itr) where {T<:Invert} = [!x for x in itr] + +# USERID gets parsed into a Symbol +struct symbol_struct2 + USERID +end; '\n' ;symbol_function(x) = x \ No newline at end of file