Skip to content

show for UnionAll types prints non-syntactic identifiers for unnamed type variables #34887

@NHDaly

Description

@NHDaly

Calling Base.show() with UnionAll types with unnamed type parameters prints those type parameters with non-syntactic generated names:

julia> Vector{<:Bool}
Array{#s16,1} where #s16<:Bool

This of course cannot be evaluated, which can be difficult when trying to understand a very large type that's printed in an error message, for example.

My first thought was that this should be fixed following the same approach as in #32408: we should change these to print via the var"" syntax, a la:

julia> Vector{<:Bool}
Array{var"#s16",1} where var"#s16"<:Bool

That seems like a fine approach, but then I noticed that if the variable does have a name, the printing mechanism seems to be able to tweak the user-provided name to prevent conflicts with other identifiers in the type! This leads me to wonder if we can use that same smarts to just pick a standard identifier name, rather than a purposefully non-standard identifier as above?
For example, notice how the user-provided name T gets renamed to T1 when there's a conflict:

julia> NTuple
Tuple{Vararg{T,N}} where T where N

julia> NTuple{N,NTuple} where N
Tuple{Vararg{Tuple{Vararg{T,N}} where T where N,N}} where N

julia> NTuple{1,NTuple{T}} where T
Tuple{Tuple{Vararg{T1,T}} where T1} where T

Can we similarly have julia just pick some arbitrary type names like p1, p2, pN... or P1, P2, ... or _T1, _T2, etc, rather than the #s16, #s17 type names we're using now? And then if there's a conflict with an actual user-provided name, it can just adjust the name like it already does?
In fact, the existing mechanism already handles conflicts even for the generated names, so this should be a very easy change: just simplifying the generated names to be valid identifiers.

julia> Vector{<:Vector{<:Bool}}
Array{#s16,1} where #s16<:(Array{#s17,1} where #s17<:Bool)

julia> Vector{<:Vector{var"#s16"}} where var"#s16" <: Bool
Array{#s17,1} where #s17<:Array{#s16,1} where #s16<:Bool

julia> Vector{<:Vector{var"#s17"}} where var"#s17" <: Bool
Array{#s171,1} where #s171<:Array{#s17,1} where #s17<:Bool

Metadata

Metadata

Assignees

No one assigned

    Labels

    display and printingAesthetics and correctness of printed representations of objects.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions