Skip to content

zeros etc. is arguably broken for mutable element types #29168

@jrevels

Description

@jrevels

Apologies if dup.

julia> mutable struct Foo
       end

julia> Base.zero(::Type{Foo}) = Foo()

julia> x = zeros(Foo, 2)
2-element Array{Foo,1}:
 Foo()
 Foo()

julia> x[1] === x[2]
true

I would've expected each element to have been instantiated separately via a new zero call. If I wanted this behavior, I would've just called fill(zero(Foo), 2).

see jump-dev/JuMP.jl#1456 (comment)
obligatory xref to #24595

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions