Skip to content

Add propagate_inbounds to new getindex method #39996

Closed
@jakobnissen

Description

@jakobnissen

MWE:

struct TextKmerIterator
    data::Vector{UInt8}
    stop::UInt # inclusive
end

function foo(x::TextKmerIterator)
    kmer, i, k = UInt(0), UInt(1), UInt(0)
    @inbounds while i  x.stop
        byte = x.data[i]
        k += one(UInt)
        i += 1
        kmer = ((kmer << 2) & UInt(0x3f)) | 0x01
        if k == 3
            return kmer, (kmer, i, k-one(UInt))
        end
    end
    return nothing
end

And then

julia> it = TextKmerIterator(collect(codeunits("T")), 4)
Main.TextKmerIterator(UInt8[0x54], 0x0000000000000004)

julia> foo(it)
ERROR: BoundsError: attempt to access 1-element Vector{UInt8} at index [2]

According to Nicholas Bauer on Slack, the culprit is

getindex(A::Array, i1::Integer, I::Integer...) = A[to_indices(A, (i1, I...))...]

added in #36427 which lacks propagate inbounds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]regressionRegression in behavior compared to a previous version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions