Skip to content

Attribute for forcing copies of mutable types #34827

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

Closed
kwasimensah opened this issue Oct 30, 2019 · 4 comments
Closed

Attribute for forcing copies of mutable types #34827

kwasimensah opened this issue Oct 30, 2019 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@kwasimensah
Copy link

I'm proposing an attribute that helps with tracking shallow copies vs deep copies/ownership semantics. I just spent a while tracking down a bug caused by this.

C++ surfaces errors like this because you're likely to pass in references as parameters but have to use values as member variables, to you're more likely to cause a copy than dangling reference

class Foo {
private /*magic_attribute */_bars : readonly string[]
constructor(bars : readonly string[]){
this._bars = bars // This line now complains because I didn't call bars.slice(0)
}
}

magic_attribute named something like owning_copy? copy_mutables?
I'm working with TypesScript 3.6.4

@nmain
Copy link

nmain commented Oct 30, 2019

See #16148

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Oct 30, 2019
@RyanCavanaugh
Copy link
Member

Please use the issue template next time. Thanks!

@kwasimensah
Copy link
Author

Ah, sorry for not seeing the template (thought it was just boilerplate about trying to find dupes).

Looking at the context bug, ownership seems well litigated. How about something that tracks frozenness? That would get the immutability check I’m really trying to get at

@kwasimensah
Copy link
Author

In case anyone else runs into this, the ReadOnly type wrappers does exactly this, carry the frozen of an an object through the type system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants