Uhm… Well, this is even minimal:
julia> struct Foo{T,S<:T} end
julia> Foo{T}(x) where T = Foo{T,T}()
julia> Foo{Float64}(1)
ERROR: UndefVarError: T not defined
Not here:
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.5.3 (2020-11-09)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> struct Foo{T<:Real, S<:AbstractMatrix{<:T}}
data::S
n::Int
function Foo{T, S}(data, n) where {T<:Real, S<:AbstractMatrix{<:T}}
Base.require_one_based_indexing(data)
new{T, S}(data, n)
end
end
julia> function Foo(A::AbstractMatrix{T}, n::Int) where {T<:Real}
return Foo{T, typeof(A)}(A, n)
end
Foo
julia> function Foo{T}(::UndefInitializer, n::Int) where {T<:Real}
d = fld(n * (n + 1), 2)
A = Matrix{T}(undef, d, d)
return Foo(A, n)
end
julia> Foo{Float64}(undef, 2)
ERROR: UndefVarError: T not defined
Stacktrace:
[1] Foo{Float64,S} where S<:(AbstractArray{var"#s1",2} where var"#s1"<:Float64)(::UndefInitializer, ::Int64) at ./REPL[3]:3
[2] top-level scope at REPL[4]:1
julia>