Skip to content

on the setindex! method #137

Open
Open
@nsajko

Description

@nsajko

I don't think you're allowed to do this:

# NOTE: for some reason, merely overloading this function causes allocations
# in Julia 1.9. This is not the case in 1.10, so presumably this is a bug.
# Therefore, allocation tests only are performed on >=1.10
function Base.setindex!(A::Array{T}, x::TempTPS, i1::Int) where {T<:TPS}
copy!(A[i1], x)
rel_temp!(x)
end

I think this only works "by accident", e.g., I suppose it could break with any Julia release, if Base decides to change its implementation regarding setindex! for Array.

It seems like type piracy, in some sense. Or perhaps it's function punning that might be confusing to users? Not sure TBH, but it definitely feels very bad.

There's another potential issue with the method signature, though an easily fixable one: it matches setindex!(::Array{Union{}}, ::TempTPS, ::Int), which is surely not intended. Fix: #136

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions