Skip to content

Commit c88db4e

Browse files
authored
Signatures: restrict color to backtrace printing (#41929)
Fixes #41928
1 parent 0974dfa commit c88db4e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

base/show.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2378,7 +2378,9 @@ end
23782378
function print_type_stacktrace(io, type; color=:normal)
23792379
str = sprint(show, type, context=io)
23802380
i = findfirst('{', str)
2381-
if i === nothing || !get(io, :backtrace, false)::Bool
2381+
if !get(io, :backtrace, false)::Bool
2382+
print(io, str)
2383+
elseif i === nothing
23822384
printstyled(io, str; color=color)
23832385
else
23842386
printstyled(io, str[1:prevind(str,i)]; color=color)

test/show.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,11 @@ let m = which(T20332{Int}(), (Int,)),
13771377
mi = Core.Compiler.specialize_method(m, Tuple{T20332{T}, Int} where T, Core.svec())
13781378
# test that this doesn't throw an error
13791379
@test occursin("MethodInstance for", repr(mi))
1380+
# issue #41928
1381+
str = sprint(mi; context=:color=>true) do io, mi
1382+
printstyled(io, mi; color=:light_cyan)
1383+
end
1384+
@test !occursin("\U1b[0m", str)
13801385
end
13811386

13821387
@test sprint(show, Main) == "Main"

0 commit comments

Comments
 (0)