Skip to content

Commit

Permalink
Signatures: restrict color to backtrace printing (#41929)
Browse files Browse the repository at this point in the history
Fixes #41928
  • Loading branch information
timholy authored Aug 23, 2021
1 parent 0974dfa commit c88db4e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2378,7 +2378,9 @@ end
function print_type_stacktrace(io, type; color=:normal)
str = sprint(show, type, context=io)
i = findfirst('{', str)
if i === nothing || !get(io, :backtrace, false)::Bool
if !get(io, :backtrace, false)::Bool
print(io, str)
elseif i === nothing
printstyled(io, str; color=color)
else
printstyled(io, str[1:prevind(str,i)]; color=color)
Expand Down
5 changes: 5 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,11 @@ let m = which(T20332{Int}(), (Int,)),
mi = Core.Compiler.specialize_method(m, Tuple{T20332{T}, Int} where T, Core.svec())
# test that this doesn't throw an error
@test occursin("MethodInstance for", repr(mi))
# issue #41928
str = sprint(mi; context=:color=>true) do io, mi
printstyled(io, mi; color=:light_cyan)
end
@test !occursin("\U1b[0m", str)
end

@test sprint(show, Main) == "Main"
Expand Down

0 comments on commit c88db4e

Please sign in to comment.