Skip to content

Commit 1fbb0f2

Browse files
committed
Fix an infinite loop when "backing up" to the signature
1 parent 4d0622b commit 1fbb0f2

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/CodeTracking.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,11 @@ function definition(method::Method, ::Type{String})
198198
end
199199
# The function declaration was presumably on a previous line
200200
lineindex = lastindex(linestarts)
201-
while !isfuncexpr(ex)
201+
while !isfuncexpr(ex) && lineindex > 0
202202
istart = linestarts[lineindex]
203203
ex, iend = Meta.parse(src, istart)
204+
lineindex -= 1
205+
line -= 1
204206
end
205207
return src[istart:iend-1]
206208
end

test/runtests.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@ isdefined(Main, :Revise) ? includet("script.jl") : include("script.jl")
1111
file, line = whereis(m)
1212
scriptpath = normpath(joinpath(@__DIR__, "script.jl"))
1313
@test file == scriptpath
14-
@test line == 3
14+
@test line == 4
1515
trace = try
1616
call_throws()
1717
catch
1818
stacktrace(catch_backtrace())
1919
end
20-
@test whereis(trace[2]) == (scriptpath, 10)
20+
@test whereis(trace[2]) == (scriptpath, 11)
2121
@test whereis(trace[3]) === nothing
2222

2323
src = definition(m, String)
2424
@test src == """
2525
function f1(x, y)
26+
# A comment
2627
return x + y
2728
end
2829
"""

test/script.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: tests are sensitive to the line number at which statements appear
22
function f1(x, y)
3+
# A comment
34
return x + y
45
end
56

0 commit comments

Comments
 (0)