Getting parent's parametric types parameter

I guess you got me on this one :slight_smile:

I have checked some of my code, and found out that the proposed solution fails on a lot of cases of this form

abstract type AbstractFoo{T}; end

Base.@kwdef struct SomeFoo{T<:Integer} <: AbstractFoo{T}
  field::Vector{T} = Vector{T}()
end

julia> sf = SomeFoo()
ERROR: UndefVarError: T not defined

julia> sf = SomeFoo{Integer}()
SomeFoo{Integer}(Integer[])

The point is that the proposed solution only works because it is able to infer the type of SomeFoo automatically. If I do

Base.@kwdef struct OtherFoo <: AbstractFoo{Integer}
  field2::Vector{Integer} = []
end

julia> of = OtherFoo()
OtherFoo(Integer[])

everyhing works nicely, but I have the Integer there multiple times again.

The solution through the type assertions could work as well, but it would be much nicer if the automatic type assertions checked this for me, without me having to hard-code all of them.

I understand that this is a niché question, so if there is no straightforward solution, I will simply move on with one of the proposed ones and my code will not be much worse. But it would be nice to have :slight_smile: