From 64875222df79a7f11d29a4b5c4c9969a6aa63fea Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Tue, 27 Feb 2024 14:14:13 +0100 Subject: [PATCH 1/2] Make dump print `const` before const fields This provides more information to the user when dumping types, and also makes the output of dump slightly more similar to the type definition syntax. Before: ``` julia> dump(BitSet) BitSet <: AbstractSet{Int64} bits::Vector{UInt64} offset::Int64 ``` After: ``` julia> dump(BitSet) BitSet <: AbstractSet{Int64} const bits::Vector{UInt64} offset::Int64 ``` --- base/show.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/base/show.jl b/base/show.jl index 217b22ab39ef8..e40b59c6af764 100644 --- a/base/show.jl +++ b/base/show.jl @@ -3007,7 +3007,9 @@ function dump(io::IOContext, x::DataType, n::Int, indent) fieldtypes = datatype_fieldtypes(x) for idx in 1:length(fields) println(io) - print(io, indent, " ", fields[idx]) + print(io, indent, " ") + isconst(x, idx) && print(io, "const ") + print(io, fields[idx]) if isassigned(fieldtypes, idx) print(io, "::") print(tvar_io, fieldtypes[idx]) From 582872ba023729dad9fe7423e49b9dbb088f5922 Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Wed, 28 Feb 2024 14:47:49 +0900 Subject: [PATCH 2/2] fix the show.jl test case --- test/show.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/show.jl b/test/show.jl index 064ae76b6fe1f..7aa0d5adbb0c5 100644 --- a/test/show.jl +++ b/test/show.jl @@ -1263,7 +1263,7 @@ let repr = sprint(dump, :(x = 1)) @test repr == "Expr\n head: Symbol =\n args: Array{Any}((2,))\n 1: Symbol x\n 2: $Int 1\n" end let repr = sprint(dump, Pair{String,Int64}) - @test repr == "Pair{String, Int64} <: Any\n first::String\n second::Int64\n" + @test repr == "Pair{String, Int64} <: Any\n const first::String\n const second::Int64\n" end let repr = sprint(dump, Tuple) @test repr == "Tuple <: Any\n"