Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Piracy fix for kwcall #171

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/piracy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,25 @@ 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)
# 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.
function_type_index += 2
end

# the first parameter in the signature is the function type, and it
# follows slightly other rules if it happens to be a Union type
is_foreign_method(signature.parameters[1], method_pkg; treat_as_own = treat_as_own) ||
return false
is_foreign_method(
signature.parameters[function_type_index],
method_pkg;
treat_as_own = treat_as_own,
) || return false

all(
return all(
param -> is_foreign(param, method_pkg; treat_as_own = treat_as_own),
signature.parameters[2:end],
signature.parameters[function_type_index+1:end],
)
end

Expand Down
3 changes: 2 additions & 1 deletion test/test_piracy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Base.findlast(::ForeignParameterizedType{Foo}, x::Int) = x + 1
# Not piracy
const MyUnion = Union{Int,Foo}
MyUnion(x::Int) = x
MyUnion(; x::Int) = x

export MyUnion

Expand Down Expand Up @@ -71,7 +72,7 @@ end
2 + # Foo constructors
1 + # Bar constructor
2 + # f
1 + # MyUnion
4 + # MyUnion (incl. kwcall)
6 + # findlast
3 + # findfirst
1 + # ForeignType callable
Expand Down
Loading