Skip to content

Commit

Permalink
Allow self in recover expressions
Browse files Browse the repository at this point in the history
This allows use of the `self` keyword in `recover` expressions,
resulting in the value being exposed as either `uni ref T` or `uni mut
T`. This isn't allowed if `self` is used inside a closure that's inside
a `recover`, as such closures can't capture `self`.

This closes #571.

Changelog: added
  • Loading branch information
yorickpeterse committed Jun 9, 2023
1 parent be0d830 commit 007495b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions compiler/src/type_check/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ impl<'a> CheckMethodBody<'a> {
node: &mut hir::SelfObject,
scope: &LexicalScope,
) -> TypeRef {
let typ = scope.surrounding_type;
let mut typ = scope.surrounding_type;

if !self.method.is_instance_method(self.db()) {
self.state.diagnostics.error(
Expand All @@ -1650,14 +1650,12 @@ impl<'a> CheckMethodBody<'a> {
return TypeRef::Error;
}

if scope.in_recover() && !typ.is_sendable(self.db()) {
self.state.diagnostics.unsendable_type_in_recover(
self.fmt(typ),
self.file(),
node.location.clone(),
);
// Closures inside a `recover` can't refer to `self`, because they can't
// capture `uni ref T` / `uni mut T` values.
self.check_if_self_is_allowed(scope, &node.location);

return TypeRef::Error;
if scope.in_recover() {
typ = typ.as_uni_ref(self.db());
}

scope.mark_closures_as_capturing_self(self.db_mut());
Expand Down

0 comments on commit 007495b

Please sign in to comment.