diff --git a/crates/red_knot_python_semantic/resources/mdtest/unreachable.md b/crates/red_knot_python_semantic/resources/mdtest/unreachable.md index f6b70c724ec20..e01ecdd314148 100644 --- a/crates/red_knot_python_semantic/resources/mdtest/unreachable.md +++ b/crates/red_knot_python_semantic/resources/mdtest/unreachable.md @@ -304,6 +304,22 @@ else: pass ``` +And for nested `if` statements: + +```py +def _(flag: bool): + if flag: + if sys.version_info >= (3, 11): + ExceptionGroup # no error here + else: + pass + + if sys.version_info < (3, 11): + pass + else: + ExceptionGroup # no error here +``` + The same works for ternary expressions: ```py 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 22af0fda06d8c..17aff301a5085 100644 --- a/crates/red_knot_python_semantic/src/semantic_index/builder.rs +++ b/crates/red_knot_python_semantic/src/semantic_index/builder.rs @@ -635,7 +635,8 @@ impl<'db> SemanticIndexBuilder<'db> { .current_visibility_constraints_mut() .add_atom(predicate_id); self.current_use_def_map_mut() - .record_reachability_constraint(visibility_constraint) + .record_reachability_constraint(visibility_constraint); + visibility_constraint } /// Record the negation of a given reachability/visibility constraint.