Skip to content

Commit

Permalink
Check for unexpected EOF in definition (#125)
Browse files Browse the repository at this point in the history
Fixes #124
  • Loading branch information
timholy authored Sep 19, 2023
1 parent eb9d401 commit 4d504df
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/CodeTracking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ 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
if !isdefined(Main, :Revise)
@test definition(String, only(methods(wrongline))) === nothing
end
end

@testset "With Revise" begin
Expand Down
3 changes: 3 additions & 0 deletions test/script.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4d504df

Please sign in to comment.