Skip to content

Fix iteration for 0-dimensional disk arrays#293

Open
sethaxen wants to merge 4 commits intoJuliaIO:mainfrom
sethaxen:0dimiter
Open

Fix iteration for 0-dimensional disk arrays#293
sethaxen wants to merge 4 commits intoJuliaIO:mainfrom
sethaxen:0dimiter

Conversation

@sethaxen
Copy link
Contributor

Fixes #289

src/iterator.jl Outdated
end
end
end
_iterate_disk(a::AbstractArray{<:Any,0}, i::Int=1) = i == 1 ? (a[], 2) : nothing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the index restricted to an Int?
According to the docstring of iterate this is supposed to be an Integer and that also works for normal Arrays.

Copy link
Contributor Author

@sethaxen sethaxen Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see now it doesn't even require the state be an Int (that's just for AbstractString). iterate(::Array, i)'s implementation has no type constraint on i and just uses it for bounds checking and indexing. Meanwhile, valid index types for AbstractArrays are CartesianIndex (implicitly not supported here due to the bounds check) or "non-boolean integer" (https://docs.julialang.org/en/v1/manual/arrays/#man-supported-index-types), so I think this would be more consistent with the Base method, as it will error whenever the Base method would error (namely, when a CartesianIndex or Bool is provided):

Suggested change
_iterate_disk(a::AbstractArray{<:Any,0}, i::Int=1) = i == 1 ? (a[], 2) : nothing
_iterate_disk(a::AbstractArray{<:Any,0}, i=1) = i == 1 ? (@inbounds a[i], 2) : nothing

Copy link
Contributor

@felixcremer felixcremer Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one equal sign to much in your function definition. Apart from that this looks good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, seems removing the Int specialization causes ambiguity with the other method. I could also remove that specialization or add it back to this method.

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

Successfully merging this pull request may close these issues.

Iteration fails for 0-dimensional disk-arrays

2 participants