Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prints symbols in Tuple{:sym} type with colons #42999

Merged
merged 4 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -993,10 +993,17 @@ function show_datatype(io::IO, @nospecialize(x::DataType), wheres::Vector=TypeVa
# Print homogeneous tuples with more than 3 elements compactly as NTuple{N, T}
if istuple
if n > 3 && all(@nospecialize(i) -> (parameters[1] === i), parameters)
print(io, "NTuple{", n, ", ", parameters[1], "}")
print(io, "NTuple{", n, ", ")
show(io, parameters[1])
print(io, "}")
else
print(io, "Tuple{")
join(io, parameters, ", ")
# join(io, params, ", ") params but `show` it
first = true
for param in parameters
first ? (first = false) : print(io, ", ")
show(io, param)
end
print(io, "}")
end
else
Expand Down
14 changes: 14 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,20 @@ test_repr("(:).a")
@test repr(Tuple{Float64, Float64, Float64, Float64}) == "NTuple{4, Float64}"
@test repr(Tuple{Float32, Float32, Float32}) == "Tuple{Float32, Float32, Float32}"

@testset "issue #42931" begin
@test repr(NTuple{4, :A}) == "NTuple{4, :A}"
@test repr(NTuple{3, :A}) == "Tuple{:A, :A, :A}"
@test repr(NTuple{2, :A}) == "Tuple{:A, :A}"
@test repr(NTuple{1, :A}) == "Tuple{:A}"
@test repr(NTuple{0, :A}) == "Tuple{}"

@test repr(Tuple{:A, :A, :A, :B}) == "Tuple{:A, :A, :A, :B}"
@test repr(Tuple{:A, :A, :A, :A}) == "NTuple{4, :A}"
@test repr(Tuple{:A, :A, :A}) == "Tuple{:A, :A, :A}"
@test repr(Tuple{:A}) == "Tuple{:A}"
@test repr(Tuple{}) == "Tuple{}"
end

# Test that REPL/mime display of invalid UTF-8 data doesn't throw an exception:
@test isa(repr("text/plain", String(UInt8[0x00:0xff;])), String)

Expand Down