<: union shorthand in NamedTuple type

(asking before opening an issue)

f(::NamedTuple{(:a,:b), Tuple{<:AbstractFloat,<:AbstractArray}}) = :notok

f(::NamedTuple{(:a,:b), Tuple{T,S}}) where
{T<:AbstractFloat,S<:AbstractArray} = :ok

The first one fails with

ERROR: NamedTuple field type must be a tuple type

while the second one works. Aren’t they supposed to be equivalent? Is this a bug, or am I not supposed to do this? Latest master, ie

julia> VERSION
v"0.7.0-beta.152"

Note:

julia> f(::NamedTuple{(:a,:b), Tuple{T,S} where {T<:AbstractArray, S<:AbstractArray}}) = :notok
ERROR: NamedTuple field type must be a tuple type
Stacktrace:
 [1] top-level scope at none:0

julia> f(::NamedTuple{(:a,:b), Tuple{T,S}}) where {T<:AbstractArray, S<:AbstractArray} = :ok
f (generic function with 1 method)
2 Likes

Thanks, this is clear (if I understand correctly, <: wraps in an immediate where).

1 Like