Skip to content

Commit f8026d2

Browse files
timholyKristoffer Carlsson
andauthored
fix lookup for kwarg functions (#61) (#63)
Co-authored-by: Kristoffer Carlsson <[email protected]>
1 parent 0823435 commit f8026d2

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/utils.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
function isfuncexpr(ex, name=nothing)
22
checkname(fdef::Expr, name) = checkname(fdef.args[1], name)
3-
checkname(fname::Symbol, name::Symbol) = fname == name
3+
checkname(fname::Symbol, name::Symbol) = begin
4+
fname === name && return true
5+
startswith(string(name), string('#', fname, '#')) && return true
6+
return false
7+
end
48
checkname(fname::Symbol, ::Nothing) = true
59

610
# Strip any macros that wrap the method definition

test/runtests.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using Test, InteractiveUtils
66

77
using CodeTracking: line_is_decl
88

9-
isdefined(Main, :Revise) ? includet("script.jl") : include("script.jl")
9+
isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.jl")
1010

1111
@testset "CodeTracking.jl" begin
1212
m = first(methods(f1))
@@ -172,3 +172,17 @@ end
172172
print("hello")
173173
end"""
174174
end
175+
176+
@testset "kwargs methods" begin
177+
m = nothing
178+
for i in 1:30
179+
s = Symbol("#func_2nd_kwarg#$i")
180+
if isdefined(Main, s)
181+
m = @eval $s
182+
end
183+
end
184+
m === nothing && error("couldn't find keyword function")
185+
body, loc = CodeTracking.definition(String, first(methods(m)))
186+
@test loc == 28
187+
@test body == "func_2nd_kwarg(; kw=2) = true"
188+
end

test/script.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ function f50() # issue #50
2323
todB(x) = 10*log10(x)
2424
println("100x is $(todB(100)) dB.")
2525
end
26+
27+
func_1st_nokwarg() = true
28+
func_2nd_kwarg(; kw=2) = true

0 commit comments

Comments
 (0)