From c28bcdbc20b48d77043f412ca166b8e9d6e65097 Mon Sep 17 00:00:00 2001 From: David Peter Date: Tue, 17 Dec 2024 14:09:58 +0100 Subject: [PATCH] Fix match control flow --- .../src/semantic_index/builder.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/red_knot_python_semantic/src/semantic_index/builder.rs b/crates/red_knot_python_semantic/src/semantic_index/builder.rs index b53c015554..9372b599cf 100644 --- a/crates/red_knot_python_semantic/src/semantic_index/builder.rs +++ b/crates/red_knot_python_semantic/src/semantic_index/builder.rs @@ -1028,23 +1028,24 @@ where let vis_constraint_id = self.record_visibility_constraint(constraint_id); vis_constraints.push(vis_constraint_id); } - for post_clause_state in post_case_snapshots { - self.flow_merge(post_clause_state); - } + + // If there is no final wildcard match case, pretend there is one. This is similar to how + // we add an implicit `else` block in if-elif chains, in case it's not present. if !cases .last() .is_some_and(|case| case.guard.is_none() && case.pattern.is_wildcard()) { - self.flow_merge(after_subject); - - // for post_clause_state in post_case_snapshots { - // self.flow_merge(post_clause_state); - // } + post_case_snapshots.push(self.flow_snapshot()); + self.flow_restore(after_subject.clone()); for id in &vis_constraints { self.record_negated_visibility_constraint(*id); } } + + for post_clause_state in post_case_snapshots { + self.flow_merge(post_clause_state); + } } ast::Stmt::Try(ast::StmtTry { body,