From 377643f9848cf88b79e7b24d1fce852eccec5e43 Mon Sep 17 00:00:00 2001 From: Jakob Peters Date: Sun, 24 Nov 2024 08:27:25 -0800 Subject: [PATCH] Highlight circular references (#56663) The text `"#= circular reference @-$d =#"` is printed yellow. Adds a test with the context `:color => true`. --- base/show.jl | 2 +- test/show.jl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/base/show.jl b/base/show.jl index e6c2367e438b3..23957d6e29b2d 100644 --- a/base/show.jl +++ b/base/show.jl @@ -443,7 +443,7 @@ function show_circular(io::IOContext, @nospecialize(x)) for (k, v) in io.dict if k === :SHOWN_SET if v === x - print(io, "#= circular reference @-$d =#") + printstyled(io, "#= circular reference @-$d =#"; color = :yellow) return true end d += 1 diff --git a/test/show.jl b/test/show.jl index de5cf32b726ee..07916c249d533 100644 --- a/test/show.jl +++ b/test/show.jl @@ -1275,6 +1275,7 @@ let x = [], y = [], z = Base.ImmutableDict(x => y) push!(y, x) push!(y, z) @test replstr(x) == "1-element Vector{Any}:\n Any[Any[#= circular reference @-2 =#], Base.ImmutableDict{Vector{Any}, Vector{Any}}([#= circular reference @-3 =#] => [#= circular reference @-2 =#])]" + @test replstr(x, :color => true) == "1-element Vector{Any}:\n Any[Any[\e[33m#= circular reference @-2 =#\e[39m], Base.ImmutableDict{Vector{Any}, Vector{Any}}([\e[33m#= circular reference @-3 =#\e[39m] => [\e[33m#= circular reference @-2 =#\e[39m])]" @test repr(z) == "Base.ImmutableDict{Vector{Any}, Vector{Any}}([Any[Any[#= circular reference @-2 =#], Base.ImmutableDict{Vector{Any}, Vector{Any}}(#= circular reference @-3 =#)]] => [Any[Any[#= circular reference @-2 =#]], Base.ImmutableDict{Vector{Any}, Vector{Any}}(#= circular reference @-2 =#)])" @test sprint(dump, x) == """ Array{Any}((1,))