Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pyrefly/lib/binding/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,8 @@ pub enum Key {
StmtExpr(TextRange),
/// I am an expression that appears in a `with` context.
ContextExpr(TextRange),
/// I am the context manager value for a `with` item without an assignment target.
ContextValue(TextRange),
/// I am the result of joining several branches.
Phi(Box<(Name, TextRange)>),
/// I am the result of narrowing a type. The two ranges are the range at which the operation is
Expand Down Expand Up @@ -960,6 +962,7 @@ impl Ranged for Key {
Self::InvalidTarget(r) => *r,
Self::StmtExpr(r) => *r,
Self::ContextExpr(r) => *r,
Self::ContextValue(r) => *r,
Self::Phi(x) => x.1,
Self::Narrow(x) => x.1,
Self::Anywhere(x) => x.1,
Expand Down Expand Up @@ -990,6 +993,7 @@ impl DisplayWith<ModuleInfo> for Key {
Self::InvalidTarget(r) => write!(f, "Key::InvalidTarget({})", ctx.display(r)),
Self::StmtExpr(r) => write!(f, "Key::StmtExpr({})", ctx.display(r)),
Self::ContextExpr(r) => write!(f, "Key::ContextExpr({})", ctx.display(r)),
Self::ContextValue(r) => write!(f, "Key::ContextValue({})", ctx.display(r)),
Self::Phi(x) => write!(f, "Key::Phi({} {})", x.0, ctx.display(&x.1)),
Self::Narrow(x) => {
write!(
Expand Down
2 changes: 1 addition & 1 deletion pyrefly/lib/binding/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ impl<'a> BindingsBuilder<'a> {
self.bind_target_no_expr(&mut opts, &make_binding);
} else {
self.insert_binding(
Key::Anon(item_range),
Key::ContextValue(item_range),
Binding::ContextValue(None, context_idx, expr_range, kind),
);
}
Expand Down
12 changes: 12 additions & 0 deletions pyrefly/lib/test/named_tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,18 @@ fn test_named_tuple_in_malformed_for_target() {
);
}

// Regression test for https://github.com/facebook/pyrefly/issues/4177
#[test]
fn test_named_tuple_in_malformed_with_item() {
// Keep the malformed source exact: adding inline expectations changes the unterminated string.
let _ = testcase_for_macro(
TestEnv::new(),
"from typing import NamedTuple\n\nwith NamedTuple('\n",
file!(),
line!(),
);
}

testcase!(
test_named_tuple_dynamic_fields,
r#"
Expand Down
Loading