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

Should zero(::AbstractArray) call fill!? #27483

Closed
tkoolen opened this issue Jun 7, 2018 · 1 comment
Closed

Should zero(::AbstractArray) call fill!? #27483

tkoolen opened this issue Jun 7, 2018 · 1 comment
Labels
arrays [a, r, r, a, y, s]

Comments

@tkoolen
Copy link
Contributor

tkoolen commented Jun 7, 2018

I thought this was just an issue in StaticArrays (JuliaArrays/StaticArrays.jl#428), but the same thing is happening in Base.

Currently:

julia> mutable struct MyNumber
           val::Float64
       end

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

julia> v = zero([MyNumber(1.0), MyNumber(2.0)])
2-element Array{MyNumber,1}:
 MyNumber(0.0)
 MyNumber(0.0)

julia> v[1].val = 1
1

julia> v
2-element Array{MyNumber,1}:
 MyNumber(1.0)
 MyNumber(1.0)

I think this is not desirable for non-isbits types.

@vtjnash
Copy link
Sponsor Member

vtjnash commented May 29, 2021

Duplicate of #29168

@vtjnash vtjnash marked this as a duplicate of #29168 May 29, 2021
@vtjnash vtjnash closed this as completed May 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s]
Projects
None yet
Development

No branches or pull requests

3 participants