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

copy!(::AbstractSet, ::AbstractSet) behaves incorrectly under aliasing (also AbstractDict) #41268

Closed
yurivish opened this issue Jun 18, 2021 · 0 comments

Comments

@yurivish
Copy link
Contributor

yurivish commented Jun 18, 2021

Mutating copy on abstract sets is implemented as union!(empty!(dst), src):

copy!(dst::AbstractSet, src::AbstractSet) = union!(empty!(dst), src)

This fails when copying a Set to itself — arguments are evaluated from left to right and the set is emptied and returned.

julia> s = Set([1, 2, 3])
Set{Int64} with 3 elements:
  2
  3
  1
julia> copy!(s, s)
Set{Int64}()

The same behavior exists for Dicts:

copy!(dst::AbstractDict, src::AbstractDict) = merge!(empty!(dst), src)

julia> d = Dict(1 => 2, 3 => 4)
Dict{Int64, Int64} with 2 entries:
  3 => 4
  1 => 2

julia> copy!(d, d)
Dict{Int64, Int64}()
@yurivish yurivish changed the title copy!(::AbstractSet, ::AbstractSet) behaves incorrectly under aliasing copy!(::AbstractSet, ::AbstractSet) behaves incorrectly under aliasing (and so does Dict) Jun 18, 2021
@yurivish yurivish changed the title copy!(::AbstractSet, ::AbstractSet) behaves incorrectly under aliasing (and so does Dict) copy!(::AbstractSet, ::AbstractSet) behaves incorrectly under aliasing (also AbstractDict) Jun 18, 2021
KristofferC pushed a commit that referenced this issue Feb 23, 2022
KristofferC pushed a commit that referenced this issue Feb 23, 2022
staticfloat pushed a commit to JuliaCI/julia-buildkite-testing that referenced this issue Mar 2, 2022
KristofferC pushed a commit that referenced this issue Mar 15, 2022
staticfloat pushed a commit that referenced this issue Dec 23, 2022
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

No branches or pull requests

1 participant