Write a constructor for these aliases?

You’re trying to find a supertype of the aliases B1/B2/B3 for the method’s dispatch that also extracts A1/A2/A3 like type parameter values for B, but the aliases actually specified A1{T}/A2{T}/A3{T} substituted with a known T value as type parameter values for B. From another angle, we can’t make a supertype B{d, a{T}} where {d, a, T} or substitute a alone; a type parameter a is not a parametric type, even if we intend it to be, so it can’t have type parameters like T.

Thing is, you don’t specifically need a type parameter, you just need a UnionAll mapping Dict(B1=>A1,B2=>A2,B3=>A3). B1/B2/B3 aliases a parametric struct B, so it has the same sole field a::TA. You can use dump to check that B1/B2/B3 specified A1/A2/A3 as the sole TA, which is how it could adopt their parameter T. That’s why fieldtypes/fieldtype(b, :a) works perfectly.

Watch out for the type instability here. d being a value would make @code_warntype indicate abstract types, but d being a type would make @code_warntype deceptively assume a constant d value. B{d}(a::AbstractA) wouldn’t be out of line.

2 Likes