You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import Base: show
immutable T
x
end
show(io::IO, t::T) = print(io, "$t.x")
println(T(1))
Results in:
fish: 'julia t.jl' terminated by signal SIGSEGV (Address boundary error)
I discovered it when I forgot to put parentheses around t.x which, I imagine, is not an uncommon mistake. I understand, of course, that this code is bound to fail because it calls for show(::T) from show(::T), and the recursion never ends, so it is not a critical bug. Nevertheless, I would expect it to fail more gracefully, like it does if you remove .x from the print call, which just gives you
ERROR: LoadError: StackOverflowError:
<... long stack trace ...>
as expected. In a longer program it would be much easier to find the mistake from a stack trace like this than just from a SIGSEGV.
The code:
Results in:
I discovered it when I forgot to put parentheses around
t.x
which, I imagine, is not an uncommon mistake. I understand, of course, that this code is bound to fail because it calls forshow(::T)
fromshow(::T)
, and the recursion never ends, so it is not a critical bug. Nevertheless, I would expect it to fail more gracefully, like it does if you remove.x
from theprint
call, which just gives youas expected. In a longer program it would be much easier to find the mistake from a stack trace like this than just from a SIGSEGV.
versioninfo()
output:Julia Version 0.5.1
Commit 6445c82 (2017-03-05 13:25 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin13.4.0)
CPU: Intel(R) Core(TM) i7-4771 CPU @ 3.50GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.7.1 (ORCJIT, haswell)
The text was updated successfully, but these errors were encountered: