Skip to content
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
9 changes: 9 additions & 0 deletions src/forwarddiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,20 @@ struct DualEltypeChecker{T}
counter::Int
DualEltypeChecker(x::T, counter::Int) where {T} = new{T}(x, counter + 1)
end

function (dec::DualEltypeChecker)(::Val{Y}) where {Y}
isdefined(dec.x, Y) || return Any
anyeltypedual(getproperty(dec.x, Y), dec.counter)
end

# use `getfield` on `Pairs`, see https://github.com/JuliaLang/julia/pull/39448
if VERSION >= v"1.7"
function (dec::DualEltypeChecker{<:Base.Pairs})(::Val{Y}) where {Y}
isdefined(dec.x, Y) || return Any
anyeltypedual(getfield(dec.x, Y), dec.counter)
end
end

# Untyped dispatch: catch composite types, check all of their fields
"""
anyeltypedual(x)
Expand Down
4 changes: 4 additions & 0 deletions test/forwarddiff_dual_detection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,7 @@ for p in p_possibilities_configs_not_inferred
u0 = ForwardDiff.Dual(2.0)
@test DiffEqBase.promote_u0(u0, p, t0) isa ForwardDiff.Dual
end

# use `getfield` on `Pairs`, see https://github.com/JuliaLang/julia/pull/39448
VERSION >= v"1.7" &&
@test_nowarn DiffEqBase.DualEltypeChecker(pairs((;)), 0)(Val(:data))