[ty] avoid standalone expressions for simple subscript targets

This commit is contained in:
Carl Meyer 2025-10-09 15:57:54 -07:00
parent 66885e4bce
commit fb11171a9b
No known key found for this signature in database
GPG Key ID: 2D1FB7916A52E121
2 changed files with 5 additions and 4 deletions

View File

@ -1626,10 +1626,11 @@ impl<'ast> Visitor<'ast> for SemanticIndexBuilder<'_, 'ast> {
self.visit_expr(&node.value); self.visit_expr(&node.value);
// Optimization for the common case: if there's just one target, and it's not an // Optimization for the common case: if there's just one target, and it's not an
// unpacking, and the target is a simple name, we don't need the RHS to be a // unpacking, and the target is a simple name or subscript, we don't need the RHS
// standalone expression at all. // to be a standalone expression at all. (We do still need standalone expressions
// for attribute targets, for implicit-attribute handling.)
if let [target] = &node.targets[..] if let [target] = &node.targets[..]
&& target.is_name_expr() && (target.is_name_expr() || target.is_subscript_expr())
{ {
self.push_assignment(CurrentAssignment::Assign { node, unpack: None }); self.push_assignment(CurrentAssignment::Assign { node, unpack: None });
self.visit_expr(target); self.visit_expr(target);

View File

@ -3215,7 +3215,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
for target in targets { for target in targets {
self.infer_target(target, value, |builder, value_expr| { self.infer_target(target, value, |builder, value_expr| {
builder.infer_standalone_expression(value_expr, TypeContext::default()) builder.infer_maybe_standalone_expression(value_expr, TypeContext::default())
}); });
} }
} }