Skip to content

Commit d1f845a

Browse files
authored
Slightly improve handling of kwcall definition lookup failure (#147)
* Improve handling of kwcall definition failure * Bump version * Add test for `kwcall` handling failure
1 parent d5d1b96 commit d1f845a

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CodeTracking"
22
uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
33
authors = ["Tim Holy <[email protected]>"]
4-
version = "2.0.0"
4+
version = "2.0.1"
55

66
[deps]
77
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

src/CodeTracking.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ function definition(::Type{String}, method::Method)
229229
p = Base.unwrap_unionall(method.sig).parameters
230230
for i = 2:length(p)
231231
T = p[i]
232+
isa(T, Core.TypeofVararg) && break # it's not our target, and there are no more arguments after this
232233
if T <: Function
233234
mstring = string(nameof(T))
234235
if startswith(mstring, '#')
@@ -237,7 +238,7 @@ function definition(::Type{String}, method::Method)
237238
end
238239
end
239240
end
240-
methodname == :kwcall && error("could not identify method name in `Core.kwcall`")
241+
methodname == :kwcall && error("could not identify method name in `Core.kwcall` (signature: $(method.sig))")
241242
end
242243
file, line = whereis(method)
243244
line == 0 && return nothing

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
292292
src, line = definition(String, m)
293293
@test occursin("::Type{P}", src)
294294
@test line == 148
295+
296+
# Graceful handling of `kwcall` definition lookup failure
297+
m = @which Core.kwcall(NamedTuple(), Union{})
298+
@test_throws "could not identify method name in `Core.kwcall`" definition(String, m)
299+
@test_throws "signature: Tuple{typeof(Core.kwcall), Any, Type{Union{}}, Vararg{Any}}" definition(String, m)
295300
end
296301

297302
@testset "With Revise" begin

0 commit comments

Comments
 (0)