Skip to content

Commit

Permalink
Fix for older julias
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Sep 5, 2023
1 parent afc5558 commit 9ac8a95
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/piracy.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Piracy

using ..Aqua: is_kwcall

if VERSION >= v"1.6-"
using Test: is_in_mods
else
Expand Down Expand Up @@ -163,7 +165,7 @@ function is_pirate(meth::Method; treat_as_own = Union{Function,Type}[])
signature = Base.unwrap_unionall(meth.sig)

function_type_index = 1
if signature.parameters[1] === typeof(Core.kwcall)
if is_kwcall(signature)
# kwcall is a special case, since it is not a real function
# but a wrapper around a function, the third parameter is the original
# function, its positional arguments follow.
Expand Down
19 changes: 19 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,22 @@ function format_diff(
$text_b
"""
end

function is_kwcall(signature::DataType)
@static if VERSION < v"1.9"
try
return length(signature.parameters) >= 3 &&
signature <: Tuple{Function,Any,Any,Vararg} &&
(
signature.parameters[3] <: Type ||
isconcretetype(signature.parameters[3])
) &&
signature.parameters[1] === Core.kwftype(signature.parameters[3])
catch err
@warn "Please open an issue on JuliaTesting/Aqua.jl for \"is_kwcall\" and the following data:" signature err
return false

Check warning on line 173 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L172-L173

Added lines #L172 - L173 were not covered by tests
end
else
return signature.parameters[1] === typeof(Core.kwcall)
end
end

0 comments on commit 9ac8a95

Please sign in to comment.