-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Open
Labels
featureIndicates new feature / enhancement requestsIndicates new feature / enhancement requeststypes and dispatchTypes, subtyping and method dispatchTypes, subtyping and method dispatch
Description
foo(@nospecialize(T::Type{<:Foo})) = T.parameters[1] is helpful when Foo is complicated and could potentially generate excessive methods otherwise (e.g., foo(::Type{<:Foo{T1,T2,...}})). Keno recently pointed out this isn't safe. I propose we standardize access to a types parameters with something like this:
getparam(x::DataType, i::Int) = x.parameters[i]
getparam(x::UnionAll, i::Int) = getparam(x.body, i)
getparam(x::TypeVar, i::Int) = getparam(x.ub, i)
getparam(x::Union, i::Int) = _combine_params(getparam(x.a, i), getparam(x.b, i))
_combine_params(a::Type, b::Type) = typejoin(a, b)
_combine_params(@nospecialize(a), @nospecialize(b)) = a === b ? a : AnyMetadata
Metadata
Assignees
Labels
featureIndicates new feature / enhancement requestsIndicates new feature / enhancement requeststypes and dispatchTypes, subtyping and method dispatchTypes, subtyping and method dispatch