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

User-code BoundsError inside a Base.getindex method silently displays as #undef #30858

Open
yurivish opened this issue Jan 27, 2019 · 1 comment
Labels
domain:arrays [a, r, r, a, y, s] domain:display and printing Aesthetics and correctness of printed representations of objects.
Milestone

Comments

@yurivish
Copy link
Contributor

Example:

struct Foo2{T, N} <: AbstractArray{T, N}
end
Base.getindex(x::Foo2, I...) = throw(BoundsError())
Base.size(x::Foo2) = (1,)

x = Foo2{Int, 1}()
println(x) # => [#undef]

This is an MWE that originally arose in a more complicated context, where I had an indexing bug that was silently turning the array into one that displayed as [#undef].

@JeffBezanson
Copy link
Sponsor Member

I think this behavior is somewhat reasonable --- with the proliferation of @inbounds annotations, you're lucky it didn't crash. There's only so much we can do to support array types that misbehave, e.g. reporting their size incorrectly.

I believe this is due to the fallback for isassigned that turns bounds errors and undef ref errors into false answers. The printing code then assumes that if isassigned returns false the element must be undefined, since it knows it only accesses valid indices. One possible (breaking) change here is for isassigned to only check for undefined elements, and throw bounds errors for out-of-bounds queries. The current behavior could be moved to haskey.

@mbauman mbauman added domain:arrays [a, r, r, a, y, s] domain:display and printing Aesthetics and correctness of printed representations of objects. labels Jan 28, 2019
@mbauman mbauman changed the title User-code BoundsError inside a Base.getindex method silently turns into #undef User-code BoundsError inside a Base.getindex method silently displays as #undef Jan 28, 2019
@LilithHafner LilithHafner added this to the 2.0 milestone Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:arrays [a, r, r, a, y, s] domain:display and printing Aesthetics and correctness of printed representations of objects.
Projects
None yet
Development

No branches or pull requests

4 participants