Minimal reproducible example - note that Foo errors, whereas Bar works.
using Zygote
using SpecialFunctions: besselk
using Test
struct Foo{Tv<:Real}
v::Vector{Tv}
function Foo(v::Real)
return new{typeof(v)}([v])
end
end
struct Bar{Tv<:Real}
v::Tv
end
function check_ad(k)
return only(Zygote.gradient(x -> besselk(only(k.v), x), 2.1))
end
@test_throws MethodError check_ad(Foo(1.5))
@test check_ad(Bar(1.5)) isa Real