Skip to content

Commit

Permalink
Highlight circular references (#56663)
Browse files Browse the repository at this point in the history
The text `"#= circular reference @-$d =#"` is printed yellow. Adds a test with the context `:color => true`.
  • Loading branch information
jakobjpeters authored Nov 24, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent fa18951 commit 377643f
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
@@ -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,))

0 comments on commit 377643f

Please sign in to comment.