Display default printing of composite types when it has a custom `show` defined

You can use Base.show_default.

For example, Measurements.jl defines custom printing of the Measurement type:

julia> using Measurements

julia> x = 3 ± 0.1
3.0 ± 0.1

julia> Base.show_default(stdout, x)
Measurement{Float64}(3.0, 0.1, 0x0000000000000003, Measurements.Derivatives((3.0, 0.1, 0x0000000000000003) => 1.0))

You can use invoke to make sure the default show method is called:

julia> struct Bar
       a
       b
       c
       end

julia> Base.show(io::IO, b::Bar) = print(io, "Bar")

julia> Bar(1,2,3)
Bar

julia> invoke(show, Tuple{IO, Any}, stdout, Bar(1,2,3))
Bar(1, 2, 3)

Also note that dump can be very useful in that exact scenario:

julia> dump(Bar(1,2,3))
Bar
  a: Int64 1
  b: Int64 2
  c: Int64 3

Tags:

Julia