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

FixedArray::deep_clone is NOT really a deep clone #1423

Open
CAIMEOX opened this issue Jan 3, 2025 · 1 comment
Open

FixedArray::deep_clone is NOT really a deep clone #1423

CAIMEOX opened this issue Jan 3, 2025 · 1 comment

Comments

@CAIMEOX
Copy link
Collaborator

CAIMEOX commented Jan 3, 2025

The implementation of deep_clone in fixedarray.mbt is not really a deep clone because it won't clone elements.

fn deep_clone[T](arr : FixedArray[T]) -> FixedArray[T] {

Unexpected behavior happens when there is internal mutability:

test {
  let arr : FixedArray[_] = [@ref.new(1), @ref.new(2), @ref.new(3)]
  let cloned = deep_clone(arr)
  arr[0].val = 0
  inspect!(cloned, content="[{val: 0}, {val: 2}, {val: 3}]")
}
@illusory0x0
Copy link
Contributor

illusory0x0 commented Jan 7, 2025

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

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy