Skip to content

Commit 3a95e31

Browse files
committed
Base: typeassert displaysize(::IOContext) return value
Improve abstract type inference. This is OK because `displaysize` is documented to always return a `Tuple{Int, Int}` value. Also add tests.
1 parent a046da5 commit 3a95e31

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

base/show.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ get(io::IO, key, default) = default
442442
keys(io::IOContext) = keys(io.dict)
443443
keys(io::IO) = keys(ImmutableDict{Symbol,Any}())
444444

445-
displaysize(io::IOContext) = haskey(io, :displaysize) ? io[:displaysize]::Tuple{Int,Int} : displaysize(io.io)
445+
displaysize(io::IOContext) = haskey(io, :displaysize) ? io[:displaysize]::Tuple{Int,Int} : displaysize(io.io)::Tuple{Int,Int}
446446

447447
show_circular(io::IO, @nospecialize(x)) = false
448448
function show_circular(io::IOContext, @nospecialize(x))

test/show.jl

+7
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,13 @@ end
17081708
"[3.141592653589793 3.141592653589793; 3.141592653589793 3.141592653589793]"
17091709
end
17101710

1711+
@testset "`displaysize` return type inference" begin
1712+
@test Tuple{Int, Int} === Base.infer_return_type(displaysize, Tuple{})
1713+
@test Tuple{Int, Int} === Base.infer_return_type(displaysize, Tuple{IO})
1714+
@test Tuple{Int, Int} === Base.infer_return_type(displaysize, Tuple{IOContext})
1715+
@test Tuple{Int, Int} === Base.infer_return_type(displaysize, Tuple{Base.TTY})
1716+
end
1717+
17111718
@testset "Array printing with limited rows" begin
17121719
arrstr = let buf = IOBuffer()
17131720
function (A, rows)

0 commit comments

Comments
 (0)