Skip to content

Commit 942021c

Browse files
authored
Merge pull request #33148 from JuliaLang/jb/printAmbigAndBottom
a couple printing improvements
2 parents 1c517a3 + 57f6739 commit 942021c

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

base/show.jl

+15-3
Original file line numberDiff line numberDiff line change
@@ -1502,8 +1502,15 @@ function show_tuple_as_call(io::IO, name::Symbol, sig::Type)
15021502
printstyled(io, name, "(...)", color=color)
15031503
return
15041504
end
1505-
sig = unwrap_unionall(sig).parameters
1506-
with_output_color(color, io) do io
1505+
tv = Any[]
1506+
env_io = io
1507+
while isa(sig, UnionAll)
1508+
push!(tv, sig.var)
1509+
env_io = IOContext(env_io, :unionall_env => sig.var)
1510+
sig = sig.body
1511+
end
1512+
sig = sig.parameters
1513+
with_output_color(color, env_io) do io
15071514
ft = sig[1]
15081515
uw = unwrap_unionall(ft)
15091516
if ft <: Function && isa(uw,DataType) && isempty(uw.parameters) &&
@@ -1523,9 +1530,10 @@ function show_tuple_as_call(io::IO, name::Symbol, sig::Type)
15231530
for i = 2:length(sig) # fixme (iter): `eachindex` with offset?
15241531
first || print(io, ", ")
15251532
first = false
1526-
print(io, "::", sig[i])
1533+
print(env_io, "::", sig[i])
15271534
end
15281535
printstyled(io, ")", color=print_style)
1536+
show_method_params(io, tv)
15291537
nothing
15301538
end
15311539

@@ -1655,6 +1663,10 @@ function dump(io::IOContext, x::SimpleVector, n::Int, indent)
16551663
end
16561664

16571665
function dump(io::IOContext, @nospecialize(x), n::Int, indent)
1666+
if x === Union{}
1667+
show(io, x)
1668+
return
1669+
end
16581670
T = typeof(x)
16591671
if isa(x, Function)
16601672
print(io, x, " (function of type ", T, ")")

doc/src/devdocs/types.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ julia> dump(Array)
9292
UnionAll
9393
var: TypeVar
9494
name: Symbol T
95-
lb: Core.TypeofBottom Union{}
95+
lb: Union{}
9696
ub: Any
9797
body: UnionAll
9898
var: TypeVar
9999
name: Symbol N
100-
lb: Core.TypeofBottom Union{}
100+
lb: Union{}
101101
ub: Any
102102
body: Array{T,N} <: DenseArray{T,N}
103103
```
@@ -178,12 +178,12 @@ TypeName
178178
wrapper: UnionAll
179179
var: TypeVar
180180
name: Symbol T
181-
lb: Core.TypeofBottom Union{}
181+
lb: Union{}
182182
ub: Any
183183
body: UnionAll
184184
var: TypeVar
185185
name: Symbol N
186-
lb: Core.TypeofBottom Union{}
186+
lb: Union{}
187187
ub: Any
188188
body: Array{T,N} <: DenseArray{T,N}
189189
cache: SimpleVector

test/ambiguous.jl

+13
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ let err = try
6767
@test lines[6] == " ambig(::Integer, ::Integer)"
6868
end
6969

70+
ambig_with_bounds(x, ::Int, ::T) where {T<:Integer,S} = 0
71+
ambig_with_bounds(::Int, x, ::T) where {T<:Integer,S} = 1
72+
let err = try
73+
ambig_with_bounds(1, 2, 3)
74+
catch _e_
75+
_e_
76+
end
77+
io = IOBuffer()
78+
Base.showerror(io, err)
79+
lines = split(String(take!(io)), '\n')
80+
@test lines[end] == " ambig_with_bounds(::$Int, ::$Int, ::T) where T<:Integer"
81+
end
82+
7083
## Other ways of accessing functions
7184
# Test that non-ambiguous cases work
7285
let io = IOBuffer()

0 commit comments

Comments
 (0)