Skip to content

Commit fafacf0

Browse files
authored
Collect items from kwfuncs (#34)
1 parent f9098fe commit fafacf0

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MethodAnalysis"
22
uuid = "85b6ec6f-f7df-4429-9514-a64bcd9ee824"
33
authors = ["Tim Holy <tim.holy@gmail.com>"]
4-
version = "0.4.8"
4+
version = "0.4.9"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

src/visit.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ function _visit(@nospecialize(operation), @nospecialize(f::Callable), visited::I
132132
_visit(operation, m, visited, print)
133133
end
134134
end
135+
# isdefined(Base, Symbol("f##kw")) is false but isdefined(Base, Symbol("#f##kw")) is true
136+
# (the type of the function is defined but the function itself isn't), so to get kwfunc we
137+
# need to look for them specially
138+
if !isa(f, Function) && isdefined(f, :instance)
139+
finst = f.instance
140+
isa(finst, Function) && _visit(operation, finst, visited, print)
141+
end
135142
return nothing
136143
end
137144

test/runtests.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ module Outer
1919

2020
f2(x, y::String) = 2x
2121
f2(x, y::Number) = x + y
22+
23+
fkw(x; y=0) = 2x + y
2224
end
2325

2426
module One
@@ -31,6 +33,18 @@ end
3133

3234

3335
@testset "visit" begin
36+
# Do we pick up kwfuncs?
37+
meths = Set{Method}()
38+
visit(Outer) do item
39+
if item isa Method
40+
push!(meths, item)
41+
return false
42+
end
43+
return true
44+
end
45+
mkw = first(methods(Core.kwfunc(Outer.fkw)))
46+
@test mkw in meths
47+
3448
@test Outer.Inner.g("hi") == 0
3549
@test Outer.f(nothing) == 1
3650
@test Outer.callh(1)

0 commit comments

Comments
 (0)