Skip to content

Commit

Permalink
Merge pull request #530 from SciML/unionall
Browse files Browse the repository at this point in the history
fix and test handling of UnionAll in isinplace checks
  • Loading branch information
ChrisRackauckas authored Oct 25, 2023
2 parents c8c3a16 + 889ee22 commit b1d71ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,15 @@ function isinplace(f, inplace_param_number, fname = "f", iip_preferred = true;
# Possible extra safety?
# Find if there's a `f(args...)` dispatch
# If so, no error
_parameters = if methods(f).ms[1].sig isa UnionAll
Base.unwrap_unionall(methods(f).ms[1].sig).parameters
else
methods(f).ms[1].sig.parameters
end

for i in 1:length(nargs)
if nargs[i] < inplace_param_number &&
any(isequal(Vararg{Any}), methods(f).ms[1].sig.parameters)
any(isequal(Vararg{Any}),_parameters)
# If varargs, assume iip
return iip_preferred
end
Expand Down
10 changes: 10 additions & 0 deletions test/function_building_error_messages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ end

@test test_num_args()

# Test isinplace on UnionAll
# https://github.com/SciML/SciMLBase.jl/issues/529

struct Foo{T} end
f = Foo{1}()
(this::Foo{T})(args...) where T=1
@test SciMLBase.isinplace(Foo{Int}(), 4)

## Problem argument tests

ftoomany(u, p, t, x, y) = 2u
u0 = 0.5
tspan = (0.0, 1.0)
Expand Down

0 comments on commit b1d71ed

Please sign in to comment.