From a5153b229a288ae253fe11c789ea875149d3d87a Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 12 Sep 2023 00:02:18 -0500 Subject: [PATCH 1/2] Check for unexpected EOF in `definition` Fixes #124 --- src/CodeTracking.jl | 4 +++- test/runtests.jl | 3 +++ test/script.jl | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/CodeTracking.jl b/src/CodeTracking.jl index b71c9b5..8172f7a 100644 --- a/src/CodeTracking.jl +++ b/src/CodeTracking.jl @@ -249,7 +249,9 @@ function definition(::Type{String}, method::Method) istart = 1 for _ = 1:line-1 push!(linestarts, istart) - istart = findnext(eol, src, istart) + 1 + istart = findnext(eol, src, istart) + istart === nothing && return nothing # unexpected EOF + istart += 1 end push!(linestarts, istart) # Parse the function definition (hoping that we've found the right location to start) diff --git a/test/runtests.jl b/test/runtests.jl index eb2657c..eaaf893 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -268,6 +268,9 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j # Parsed result gives a symbol instead of expression m = @which symbol_function(1) @test_nowarn definition(String, m) + + # #124 + @test definition(String, only(methods(wrongline))) === nothing end @testset "With Revise" begin diff --git a/test/script.jl b/test/script.jl index a46de79..61b4f23 100644 --- a/test/script.jl +++ b/test/script.jl @@ -139,3 +139,6 @@ let argnames = :args end end) end + +wrongline() = 1 # for use testing #124 +only(methods(wrongline)).line = 9999 # unclear how it happened in the wild, but this at least catches the problem From 93f7902b44cbf3a59f7b5edb3da7e00147515dc5 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 12 Sep 2023 00:44:56 -0500 Subject: [PATCH 2/2] Make conditional on not having Revise --- test/runtests.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index eaaf893..ccca744 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -270,7 +270,9 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j @test_nowarn definition(String, m) # #124 - @test definition(String, only(methods(wrongline))) === nothing + if !isdefined(Main, :Revise) + @test definition(String, only(methods(wrongline))) === nothing + end end @testset "With Revise" begin