-
Notifications
You must be signed in to change notification settings - Fork 170
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
chore: fix unmutable environment #5016
base: master
Are you sure you want to change the base?
Conversation
…ype checking for mutable capture that's not a reference, add two unit tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding a type check on a lambda's environment, can we avoid making the captured variables mutable in the first place? When the lookup is performed in name resolution there should be a check to look up a variable from an outer function. We should ensure there that the variable is introduced only as immutable if possible.
let captured_vars = | ||
match self.ensure_mutable_captures_have_ref(expr_id, lambda.captures) { | ||
Err(err) => { | ||
self.errors.push(err); | ||
return Type::Error; | ||
} | ||
Ok(captured_vars) => captured_vars, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let captured_vars = | |
match self.ensure_mutable_captures_have_ref(expr_id, lambda.captures) { | |
Err(err) => { | |
self.errors.push(err); | |
return Type::Error; | |
} | |
Ok(captured_vars) => captured_vars, | |
}; | |
let Ok(captured_vars) = self.ensure_mutable_captures_have_ref(expr_id, lambda.captures) else { | |
self.errors.push(err); | |
return Type::Error; | |
}; |
Description
Problem*
Resolves #4795
Summary*
This PR simply adds a check on mutable captures: when not
&mut
, a type checking error is thrown.Additional Context
Documentation*
Check one:
PR Checklist*
cargo fmt
on default settings.