-
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
You can easily omit mutable flag for a variable if you do this:
fn unmut (a: ref int) ref int {
return a
}
main {
a := 10
mut aMut := unmut(ref a)
}
One way to solve it by making all ReturnStatement return immutable value that can't be modified, unless specified otherwise with Mutable generic:
fn unmut (mut a: ref int) Mutable<ref int> {
return a
}
main {
mut a := 10
mut aMut := unmut(ref a)
}
Fail if trying to get mutable value out of immutable return:
fn unmut (a: ref int) Mutable<ref int> {
return a // error: `a` is immutable
}
main {
mut a := 10
mut aMut := unmut(ref a)
}
Fail if trying to assign immutable variable to Mutable generic:
fn unmut2 (a: ref int) Mutable<ref int> {
return a // error: `a` is immutable
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request