-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segfault when defining show for types #22363
Comments
I see a julia> struct Null end
julia> Base.show(io::IO, ::Type{Union{T, Null}}) where {T} = print(io, "?$T")
julia> struct WeakRefString{T} end
julia> Base.show(io::IO, ::Type{WeakRefString{T}}) where {T} = print(io, "WeakRefString{$T}")
julia> temp = [] The backtrace repeats this snippet:
|
Note |
I think the best way to make this work --- even though I never condone defining |
The other alternative that seems to work is by also defining It also seems like this would be a great use-case for being able to specify "only-the-strict-subtypes-of-T" as a subtype relation; not sure if that's ever been brought up before or is possible at all, but seems like that would be a workable solution here. |
But why does it need the second |
Very valid question @martinholters ! |
Just found this, which might be related: #13306 |
Something isn't invalidated correctly: julia> struct Null end
julia> struct WeakRefString{T} end
julia> methods(show, Tuple{IO,Type{Any}})
# 1 method for generic function "show":
[1] show(io::IO, x::DataType) in Base at show.jl:211
julia> foo() = show(Any)
foo (generic function with 1 method)
julia> foo()
Any
julia> Base.show(io::IO, ::Type{Union{T, Null}}) where {T} = print(io, "?$T")
julia> methods(show, Tuple{IO,Type{Any}})
# 1 method for generic function "show":
[1] show(io::IO, ::Type{Union{Null, T}}) where T in Main at REPL[6]:1
julia> foo()
Any
julia> show(Any)
?Any So julia> Base.show(io::IO, ::Type{WeakRefString{T}}) where {T} = print(io, "WeakRefString{$T}")
julia> foo()
Any
julia> show(Any)
ERROR: StackOverflowError:
[...] |
Further reduced a bit: julia> foo(::DataType) = 1
foo (generic function with 1 method)
julia> bar() = foo(Any)
bar (generic function with 1 method)
julia> bar()
1
julia> foo(::Type{Union{T,Void}}) where {T} = 2
foo (generic function with 2 methods)
julia> foo(Any)
2
julia> bar()
1 |
bump |
This appears to be fixed now, though I will reiterate Jeff's warning not to define show for particular types |
Here's the minimum repro
Note the last thing that happens is it's trying to display
0-element Array{Any,1}
.The text was updated successfully, but these errors were encountered: