Skip to content

Commit be6f599

Browse files
committed
Improve validType checks for UnionAll types
1 parent 36bc775 commit be6f599

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/RecoPlans/RecoPlans.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ function setvalue!(plan::RecoPlan{T}, name::Symbol, x::X) where {T, X}
7474

7575
t = type(plan, name)
7676
if validvalue(plan, t, x)
77-
X <: t || X <: RecoPlan{<:t} || ismissing(x)
7877
getfield(plan, :values)[name] = x
7978
else
8079
getfield(plan, :values)[name] = convert(t, x)
@@ -93,6 +92,9 @@ end
9392
validvalue(plan, t, value::Missing) = true
9493
validvalue(plan, ::Type{T}, value::X) where {T, X <: T} = true
9594
validvalue(plan, ::Type{T}, value::RecoPlan{<:T}) where T = true
95+
# RecoPlans are stripped of parameters
96+
validvalue(plan, t::UnionAll, ::RecoPlan{T}) where T = T <: t || T <: Base.typename(t).wrapper # Last case doesnt work for Union{...} that is a UnionAll, such as ProcessCache Unio
97+
validvalue(plan, t::Type{Union}, value) = validvalue(plan, t.a, value) || validvalue(plan, t.b, value)
9698
validvalue(plan, t, value) = false
9799

98100
#X <: t || X <: RecoPlan{<:t} || ismissing(x)
@@ -113,7 +115,7 @@ function setAll!(plan::RecoPlan{T}, name::Symbol, x) where {T<:AbstractImageReco
113115
for (key, nested) in nestedPlans
114116
key != name && setAll!(nested, name, x)
115117
end
116-
if haskey(fields, name)
118+
if hasproperty(plan, name)
117119
try
118120
plan[name] = x
119121
catch ex

0 commit comments

Comments
 (0)