Skip to content

Commit 4d504df

Browse files
authored
Check for unexpected EOF in definition (#125)
Fixes #124
1 parent eb9d401 commit 4d504df

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/CodeTracking.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ function definition(::Type{String}, method::Method)
249249
istart = 1
250250
for _ = 1:line-1
251251
push!(linestarts, istart)
252-
istart = findnext(eol, src, istart) + 1
252+
istart = findnext(eol, src, istart)
253+
istart === nothing && return nothing # unexpected EOF
254+
istart += 1
253255
end
254256
push!(linestarts, istart)
255257
# Parse the function definition (hoping that we've found the right location to start)

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
268268
# Parsed result gives a symbol instead of expression
269269
m = @which symbol_function(1)
270270
@test_nowarn definition(String, m)
271+
272+
# #124
273+
if !isdefined(Main, :Revise)
274+
@test definition(String, only(methods(wrongline))) === nothing
275+
end
271276
end
272277

273278
@testset "With Revise" begin

test/script.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,6 @@ let argnames = :args
139139
end
140140
end)
141141
end
142+
143+
wrongline() = 1 # for use testing #124
144+
only(methods(wrongline)).line = 9999 # unclear how it happened in the wild, but this at least catches the problem

0 commit comments

Comments
 (0)