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

fix and test handling of UnionAll in isinplace checks #530

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 @@
# 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

Check warning on line 260 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L259-L260

Added lines #L259 - L260 were not covered by tests
else
methods(f).ms[1].sig.parameters

Check warning on line 262 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L262

Added line #L262 was not covered by tests
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
Loading