I am in a confusing situation where I cannot find out why a method is not found.
Since it’s hard to explain I will directly post the MWE.
using Test
abstract type RSAState end
abstract type RSAAction end
abstract type RSAPOMDP{S<:RSAState,A<:RSAAction} end
struct RSAPOMDPState1 <: RSAState end
struct RSAPOMDPAction1 <: RSAAction end
struct RSAPOMDP1{S,A} <: RSAPOMDP{S,A} end
getdatatype(u::UnionAll) = getdatatype(u.body)
getdatatype(u) = u
statetype1(t::UnionAll) = statetype1(getdatatype(t))
# what I would consider enough
statetype1(t::Type{T}) where {T<:RSAPOMDP} = t.parameters[1]
statetype2(t::UnionAll) = statetype2(getdatatype(t))
# what actually works
statetype2(t::Type{T}) where {S,A,T<:RSAPOMDP{S,A}} = t.parameters[1]
RSAPOMDP1_1_1_2 = RSAPOMDP1{RSAPOMDPState1}
@testset let
#fail but shouldn't
@test_throws MethodError statetype1(RSAPOMDP1_1_1_2)
# doesn't fail
@test statetype2(RSAPOMDP1_1_1_2) === RSAPOMDPState1
end
To me statetype2(t::Type{T})
is a verbose version of statetype1(t::Type{T})
, so it is unexpected why statetype2
only works.
Is this a bug or a design choice?
In case that’s desired, can somebody explain why ?