Skip to content
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

Calling the "repr" function on an object which both auto-reference itself and inherits from "Function" cause a StackOverflowError #37522

Open
AFatNiBBa opened this issue Sep 11, 2020 · 0 comments

Comments

@AFatNiBBa
Copy link

struct a <: Function
	x::Dict
end

The struct "a" inherit from the abstract type "Function" and contains a "Dict"

b = a(Dict{Any, Any}(1 => 1, 2 => 2, 3 => 3))
#output:
# (::a) (generic function with 0 methods)

b.x[2] = b
#output:
# (::a) (generic function with 0 methods)

The struct gets instantiated and an element of the field "x" is assigned with the instance itself

repr(b)
#output:
# ERROR: StackOverflowError:
# Stacktrace:
#  [1] _show_default(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Any) at .\show.jl:396
#  [2] show_default at .\show.jl:389 [inlined]
#  [3] show_function(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Function, ::Bool) at .\show.jl:445
#  [4] print(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Function) at .\show.jl:461
#  [5] print_to_string(::Function) at .\strings\io.jl:135
#  [6] string at .\strings\io.jl:174 [inlined]
#  [7] Symbol at .\strings\basic.jl:227 [inlined]
#  [8] isdelimited(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::Function) at .\show.jl:664
#  [9] show(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::Pair{Any,Any}) at .\show.jl:682
#  [10] show(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::Dict{Any,Any}) at .\dict.jl:38
#  [11] _show_default(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Any) at .\show.jl:406
#  ... (the last 10 lines are repeated 5022 more times)
#  [50232] show_default at .\show.jl:389 [inlined]
#  [50233] show_function(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Function, ::Bool) at .\show.jl:445
#  [50234] show(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Function) at .\show.jl:460
#  [50235] sprint(::Function, ::Function; context::Nothing, sizehint::Int64) at .\strings\io.jl:105
#  [50236] #repr#356 at .\strings\io.jl:227 [inlined]
#  [50237] repr(::Function) at .\strings\io.jl:227

When calling the "repr" function on the object it gives a StackOverflowError, but it is not normal since the function can handle circular references.
I don't think I'm the one that made the mistake because executing the same code but with"a" not being a subtype of "Function" goes as expected:

struct a
	x::Dict
end

b = a(Dict{Any, Any}(1 => 1, 2 => 2, 3 => 3))
#output:
# (::a) (generic function with 0 methods)

b.x[2] = b
#output:
# (::a) (generic function with 0 methods)

repr(b)
#output:
# "a(Dict{Any,Any}(2 => a(#= circular reference @-2 =#),3 => 3,1 => 1))"

#=
Julia Version 1.5.1
Commit 697e782ab8 (2020-08-25 20:08 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: AMD Ryzen 5 3600 6-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, znver2)
=#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant