-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Recovering to owned values when assigning fields
When assigning a process' field, we allow the value type to be owned provided it originated from a `recover` expression, allowing for code such as this: class async Foo[T] { let @field: T } Foo { @field = recover { ... } } This way one can take `uni T` values as input but explicitly store them as owned `T` values. This commit also fixes a bug where it would be possible to assign process field values using the syntax `receiver.process = value`, which shouldn't be allowed. This fixes #641. Changelog: added
- Loading branch information
1 parent
c9c01ac
commit 1b61961
Showing
5 changed files
with
95 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
std/test/diagnostics/assign_async_field_recover_owned.inko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class async Thing[A, B] { | ||
let @a: A | ||
let @b: B | ||
|
||
fn static new(a: A, b: uni B) -> Thing[A, B] { | ||
Thing { @a = a, @b = recover b } | ||
} | ||
} | ||
|
||
# assign_async_field_recover_owned.inko:6:18 error(invalid-symbol): the field 'a' can't be assigned a value of type 'A', as it's not sendable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class async Foo { | ||
let @value: Int | ||
|
||
fn async mut update(value: Int) { | ||
# This is OK because it's safe to assign fields from within the process that | ||
# owns them. | ||
@value = value | ||
} | ||
} | ||
|
||
fn example { | ||
let foo = Foo { @value = 42 } | ||
|
||
foo.value | ||
foo.value = 50 | ||
} | ||
|
||
# process_fields.inko:14:3 error(invalid-symbol): the field 'value' can only be used by the owning process | ||
# process_fields.inko:15:3 error(invalid-symbol): the field 'value' can only be used by the owning process |