Skip to content

Commit 40108d8

Browse files
stroxlerfacebook-github-bot
authored andcommitted
Reorder a bit of bind_target_impl
Summary: This function is tricky to refactor and I need some nontrivial ordering changes to cut over from `Fn` to `FnOnce`. This diff does the easy part of the reordering. Reviewed By: yangdanny97 Differential Revision: D75422387 fbshipit-source-id: 288b69bcb9e92df7c844ccf6cb611ac1439d3ef2
1 parent 8901d71 commit 40108d8

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pyrefly/lib/binding/target.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,7 @@ impl<'a> BindingsBuilder<'a> {
179179
make_assigned_value: &dyn Fn(Option<Idx<KeyAnnotation>>) -> ExprOrBinding,
180180
is_aug_assign: bool,
181181
) {
182-
if is_aug_assign && let Expr::Name(name) = target {
183-
// We normally should not ensure a top-level name, but if the target is for an
184-
// AugAssign operation, then the name needs to already be in scope and will be used
185-
// to resolve the target as a (possibly overwriting) mutation.
186-
self.ensure_mutable_name(name);
187-
} else if matches!(target, Expr::Subscript(..) | Expr::Attribute(..)) {
182+
if matches!(target, Expr::Subscript(..) | Expr::Attribute(..)) {
188183
// We should always ensure a target that is an attribute or subscript, because
189184
// the base needs to already be in scope and will be used to resolve the target as
190185
// a mutation.
@@ -195,7 +190,15 @@ impl<'a> BindingsBuilder<'a> {
195190
ExprOrBinding::Binding(b) => b,
196191
};
197192
match target {
198-
Expr::Name(name) => self.bind_assign(name, make_binding, FlowStyle::None),
193+
Expr::Name(name) => {
194+
if is_aug_assign {
195+
// We normally should not ensure a top-level name, but if the target is for an
196+
// AugAssign operation, then the name needs to already be in scope and will be used
197+
// to resolve the target as a (possibly overwriting) mutation.
198+
self.ensure_mutable_name(name);
199+
}
200+
self.bind_assign(name, make_binding, FlowStyle::None);
201+
}
199202
Expr::Attribute(x) => {
200203
// Create a binding to verify that the assignment is valid and potentially narrow
201204
// the name assigned to.

0 commit comments

Comments
 (0)