Skip to content

Commit 265d33a

Browse files
authored
Handle Vararg specializations (#45)
Fixes #44
1 parent 27a263f commit 265d33a

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
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.12"
4+
version = "0.4.13"
55

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

src/findcallers.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ function findcallers(f, argmatch::Union{Function,Nothing}, mis::AbstractVector{C
155155
matches || continue
156156
# Collect the arg types
157157
argtypes = []
158-
for i = (callhead === :iterate ? 4 : 2):length(stmt.args)
159-
a = stmt.args[i]
158+
for iarg = (callhead === :iterate ? 4 : 2):length(stmt.args)
159+
a = stmt.args[iarg]
160160
if isa(a, Core.SSAValue)
161161
push!(argtypes, extract(src.ssavaluetypes[a.id], sparams))
162162
elseif isa(a, Core.SlotNumber)
@@ -165,7 +165,8 @@ function findcallers(f, argmatch::Union{Function,Nothing}, mis::AbstractVector{C
165165
push!(argtypes, Core.Typeof(getfield(a.mod, a.name)))
166166
elseif isexpr(a, :static_parameter)
167167
a = a::Expr
168-
push!(argtypes, Type{sparams[a.args[1]::Int]})
168+
T = sparams[a.args[1]::Int]
169+
push!(argtypes, Base.isvarargtype(T) ? T : Type{T})
169170
else
170171
push!(argtypes, extract(a, sparams))
171172
end

test/runtests.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ if !isdefined(Base, :only)
1111
end
1212
end
1313

14+
# For testing #44 (from Pkg)
15+
struct LikeVersionBound
16+
t::NTuple{3,UInt32}
17+
n::Int
18+
function LikeVersionBound(tin::NTuple{n,Integer}) where n
19+
n <= 3 || throw(ArgumentError("LikeVersionBound: you can only specify major, minor and patch versions"))
20+
n == 0 && return new((0, 0, 0), n)
21+
n == 1 && return new((tin[1], 0, 0), n)
22+
n == 2 && return new((tin[1], tin[2], 0), n)
23+
n == 3 && return new((tin[1], tin[2], tin[3]), n)
24+
error("invalid $n")
25+
end
26+
end
27+
1428
module Outer
1529
module Inner
1630
g(::AbstractString) = 0
@@ -462,6 +476,12 @@ if isdefined(MethodAnalysis, :findcallers)
462476
callers2 = findcallers(OtherModule.h, nothing, mis)
463477
@test length(callers2) == 1
464478

479+
# issue #44
480+
m = only(methods(LikeVersionBound))
481+
mi = Core.Compiler.specialize_method(m, Tuple{Type{LikeVersionBound}, Tuple{Int, Vararg{Int}}}, Core.svec())
482+
argmatch(typs) = length(typs) >= 2 && typs[2] === AbstractArray
483+
findcallers(convert, argmatch, [mi])
484+
465485
# show
466486
io = IOBuffer()
467487
print(io, cm)

0 commit comments

Comments
 (0)