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

Result of calling langlib methods on immutable values #646

Closed
MaryamZi opened this issue Nov 6, 2020 · 3 comments
Closed

Result of calling langlib methods on immutable values #646

MaryamZi opened this issue Nov 6, 2020 · 3 comments

Comments

@MaryamZi
Copy link
Member

MaryamZi commented Nov 6, 2020

Description:
When langlib methods that create new values are called on immutable values, will the resultant value also be immutable?

For example, where arr is

int[] & readonly arr = [1, 2, 1];

should the static type and the inherent type of the value created by

arr.filter(val => val > 1)

be int[] or int[] & readonly?

Based on #551 (comment), do we only consider the element type and not the read-only bit of the array type itself?

Related Issues:
#391
#551

@jclark
Copy link
Collaborator

jclark commented Nov 7, 2020

A langlib function like filter is parameterized the member type, so the static type of the collection wouldn't pick up the readonly (unless we do #521). But readonly does get pushed down to the member type. So, for example, if the static type T of the array is readonly & (json[]), then the most precise type M such that the T is a subtype of M[] is would make M be readonly & json (since readonly & (json[]) is subtype of (readonly & json)[]).

So in general if the argument type is T[] & readonly the static type and inherent type of the return value would be (readonly & T)[].

@jclark
Copy link
Collaborator

jclark commented Nov 7, 2020

#187 should say something about this.

@jclark jclark closed this as completed Nov 7, 2020
@MaryamZi
Copy link
Member Author

MaryamZi commented Nov 7, 2020

Noted, thank you.

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