From a4df3247f88945e111c1860f5c6a965a7034418a Mon Sep 17 00:00:00 2001
From: Christopher Rackauckas <accounts@chrisrackauckas.com>
Date: Mon, 28 Oct 2024 07:33:30 -0100
Subject: [PATCH 1/3] Handle empty Kwargs case in forwarddiff detection

Fixes https://github.com/SciML/DiffEqBase.jl/issues/1074
---
 src/forwarddiff.jl                 | 5 ++++-
 test/forwarddiff_dual_detection.jl | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/forwarddiff.jl b/src/forwarddiff.jl
index f05918008..ec3612fa3 100644
--- a/src/forwarddiff.jl
+++ b/src/forwarddiff.jl
@@ -363,11 +363,14 @@ function anyeltypedual(x::NamedTuple, ::Type{Val{counter}} = Val{0}) where {coun
     anyeltypedual(values(x))
 end
 
-function DiffEqBase.anyeltypedual(
+function anyeltypedual(
         f::SciMLBase.AbstractSciMLFunction, ::Type{Val{counter}}) where {counter}
     Any
 end
 
+anyeltypedual(::@Kwargs{}, ::Type{Val{counter}} = Val{0}) where {counter} = Any
+anyeltypedual(::Type{@Kwargs{}}, ::Type{Val{counter}} = Val{0}) where {counter} = Any
+
 @inline promote_u0(::Nothing, p, t0) = nothing
 
 @inline function promote_u0(u0, p, t0)
diff --git a/test/forwarddiff_dual_detection.jl b/test/forwarddiff_dual_detection.jl
index f3417d58d..26cbfd5cd 100644
--- a/test/forwarddiff_dual_detection.jl
+++ b/test/forwarddiff_dual_detection.jl
@@ -36,7 +36,7 @@ p_possibilities = [ForwardDiff.Dual(2.0), (ForwardDiff.Dual(2.0), 2.0),
     (; x = 2.0, y = [ForwardDiff.Dual(2.0)]), (; x = 2.0, y = [[ForwardDiff.Dual(2.0)]]),
     Set([2.0, ForwardDiff.Dual(2.0)]), (SciMLBase.NullParameters(), ForwardDiff.Dual(2.0)),
     ((), ForwardDiff.Dual(2.0)), ForwardDiff.Dual{Nothing}(ForwardDiff.Dual{MyStruct}(2.0)),
-    (plot(), ForwardDiff.Dual(2.0)), [(1.0, ForwardDiff.Dual(1.0, (1.0,)))]
+    (plot(), ForwardDiff.Dual(2.0)), [(1.0, ForwardDiff.Dual(1.0, (1.0,))), pairs((;))]
 ]
 
 for p in p_possibilities

From d5c2d4c874a44cba772a68aff30ba43ac5431760 Mon Sep 17 00:00:00 2001
From: Christopher Rackauckas <accounts@chrisrackauckas.com>
Date: Mon, 28 Oct 2024 07:39:48 -0100
Subject: [PATCH 2/3] fix test

---
 test/forwarddiff_dual_detection.jl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/test/forwarddiff_dual_detection.jl b/test/forwarddiff_dual_detection.jl
index 26cbfd5cd..9a5cb2e33 100644
--- a/test/forwarddiff_dual_detection.jl
+++ b/test/forwarddiff_dual_detection.jl
@@ -36,7 +36,7 @@ p_possibilities = [ForwardDiff.Dual(2.0), (ForwardDiff.Dual(2.0), 2.0),
     (; x = 2.0, y = [ForwardDiff.Dual(2.0)]), (; x = 2.0, y = [[ForwardDiff.Dual(2.0)]]),
     Set([2.0, ForwardDiff.Dual(2.0)]), (SciMLBase.NullParameters(), ForwardDiff.Dual(2.0)),
     ((), ForwardDiff.Dual(2.0)), ForwardDiff.Dual{Nothing}(ForwardDiff.Dual{MyStruct}(2.0)),
-    (plot(), ForwardDiff.Dual(2.0)), [(1.0, ForwardDiff.Dual(1.0, (1.0,))), pairs((;))]
+    (plot(), ForwardDiff.Dual(2.0)), [(1.0, ForwardDiff.Dual(1.0, (1.0,)))]
 ]
 
 for p in p_possibilities
@@ -162,7 +162,7 @@ for p in p_possibilities_missed
 end
 
 p_possibilities_notdual = [
-    (), (;), [2.0], [2.0, 2], [2.0, (2.0)], [2.0, MyStruct(2.0, 2.0f0)]
+    (), (;), [2.0], [2.0, 2], [2.0, (2.0)], [2.0, MyStruct(2.0, 2.0f0), pairs((;))]
 ]
 
 for p in p_possibilities_notdual

From 67d2c8ff567b0ba9090e1c658bc64c60c42a8e6f Mon Sep 17 00:00:00 2001
From: Christopher Rackauckas <accounts@chrisrackauckas.com>
Date: Mon, 28 Oct 2024 09:40:57 -0100
Subject: [PATCH 3/3] fix test

---
 test/forwarddiff_dual_detection.jl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/forwarddiff_dual_detection.jl b/test/forwarddiff_dual_detection.jl
index 9a5cb2e33..292c48d9e 100644
--- a/test/forwarddiff_dual_detection.jl
+++ b/test/forwarddiff_dual_detection.jl
@@ -162,7 +162,7 @@ for p in p_possibilities_missed
 end
 
 p_possibilities_notdual = [
-    (), (;), [2.0], [2.0, 2], [2.0, (2.0)], [2.0, MyStruct(2.0, 2.0f0), pairs((;))]
+    (), (;), [2.0], [2.0, 2], [2.0, (2.0)], [2.0, MyStruct(2.0, 2.0f0)], pairs((;))
 ]
 
 for p in p_possibilities_notdual