Skip to content

Commit b27ce8f

Browse files
authored
Merge pull request #56 from timholy/teh/fix50
Handle inner functions (fixes #50)
2 parents ab7a770 + c4065b5 commit b27ce8f

File tree

5 files changed

+19
-48
lines changed

5 files changed

+19
-48
lines changed

appveyor.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/CodeTracking.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ function definition(::Type{String}, method::Method)
209209
end
210210
ex, iend = Meta.parse(src, istart)
211211
iend = prevind(src, iend)
212-
if isfuncexpr(ex)
212+
if isfuncexpr(ex, method.name)
213213
iend = min(iend, lastindex(src))
214214
return strip(src[istart:iend], '\n'), line
215215
end
216216
# The function declaration was presumably on a previous line
217217
lineindex = lastindex(linestarts)
218-
while !isfuncexpr(ex) && lineindex > 0
218+
while !isfuncexpr(ex, method.name) && lineindex > 0
219219
istart = linestarts[lineindex]
220220
try
221221
ex, iend = Meta.parse(src, istart)

src/utils.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
function isfuncexpr(ex)
1+
function isfuncexpr(ex, name=nothing)
2+
checkname(fdef::Expr, name) = checkname(fdef.args[1], name)
3+
checkname(fname::Symbol, name::Symbol) = fname == name
4+
checkname(fname::Symbol, ::Nothing) = true
5+
26
# Strip any macros that wrap the method definition
37
while isexpr(ex, :macrocall) && length(ex.args) == 3
48
ex = ex.args[3]
59
end
610
isa(ex, Expr) || return false
7-
ex.head == :function && return true
11+
ex.head == :function && return checkname(ex, name)
812
if ex.head == :(=)
913
a = ex.args[1]
1014
if isa(a, Expr)
1115
while a.head == :where
1216
a = a.args[1]
1317
isa(a, Expr) || return false
1418
end
15-
a.head == :call && return true
19+
a.head == :call && return checkname(a, name)
1620
end
1721
end
1822
return false

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ isdefined(Main, :Revise) ? includet("script.jl") : include("script.jl")
4646
@test startswith(src, "@inline")
4747
@test line == 16
4848

49+
m = first(methods(f50))
50+
src, line = definition(String, m)
51+
@test occursin("100x", src)
52+
@test line == 22
53+
4954
info = CodeTracking.PkgFiles(Base.PkgId(CodeTracking))
5055
@test Base.PkgId(info) === info.id
5156
@test CodeTracking.basedir(info) == dirname(@__DIR__)

test/script.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ f2(x, y) = x + y
1818
z = x + 1
1919
return z
2020
end
21+
22+
function f50() # issue #50
23+
todB(x) = 10*log10(x)
24+
println("100x is $(todB(100)) dB.")
25+
end

0 commit comments

Comments
 (0)