Skip to content

Commit a9c2e27

Browse files
omusJeffBezanson
authored andcommitted
Append newline to the end of dump methods (#17202)
* Append newline to the end of dump methods * Made dump methods return nothing
1 parent e90bcf3 commit a9c2e27

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

base/show.jl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,7 @@ function dump(io::IO, x::SimpleVector, n::Int, indent)
10401040
end
10411041
end
10421042
end
1043+
isempty(indent) && println(io)
10431044
nothing
10441045
end
10451046

@@ -1065,6 +1066,7 @@ function dump(io::IO, x::ANY, n::Int, indent)
10651066
else
10661067
!isa(x,Function) && print(io, " ", x)
10671068
end
1069+
isempty(indent) && println(io)
10681070
nothing
10691071
end
10701072

@@ -1102,12 +1104,21 @@ function dump(io::IO, x::Array, n::Int, indent)
11021104
end
11031105
end
11041106
end
1107+
isempty(indent) && println(io)
1108+
nothing
1109+
end
1110+
function dump(io::IO, x::Symbol, n::Int, indent)
1111+
print(io, typeof(x), " ", x)
1112+
isempty(indent) && println(io)
11051113
nothing
11061114
end
1107-
dump(io::IO, x::Symbol, n::Int, indent) = print(io, typeof(x), " ", x)
11081115

11091116
# Types
1110-
dump(io::IO, x::Union, n::Int, indent) = print(io, x)
1117+
function dump(io::IO, x::Union, n::Int, indent)
1118+
print(io, x)
1119+
isempty(indent) && println(io)
1120+
nothing
1121+
end
11111122

11121123
function dump(io::IO, x::DataType, n::Int, indent)
11131124
print(io, x)
@@ -1124,6 +1135,7 @@ function dump(io::IO, x::DataType, n::Int, indent)
11241135
end
11251136
end
11261137
end
1138+
isempty(indent) && println(io)
11271139
nothing
11281140
end
11291141

@@ -1167,6 +1179,8 @@ function dumptype(io::IO, x::ANY, n::Int, indent)
11671179
end
11681180
end
11691181
end
1182+
isempty(indent) && println(io)
1183+
nothing
11701184
end
11711185

11721186
# For abstract types, use _dumptype only if it's a form that will be called

test/show.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,3 +500,9 @@ let s = IOBuffer(Array{UInt8}(0), true, true)
500500
Base.showarray(s, [1,2,3], false, header = false)
501501
@test String(resize!(s.data, s.size)) == " 1\n 2\n 3"
502502
end
503+
504+
# The `dump` function should alway have a trailing newline
505+
let io = IOBuffer()
506+
dump(io, :(x = 1))
507+
@test takebuf_string(io)[end] == '\n'
508+
end

0 commit comments

Comments
 (0)