diff --git a/crates/ruff/resources/test/fixtures/pyflakes/F811_22.py b/crates/ruff/resources/test/fixtures/pyflakes/F811_22.py new file mode 100644 index 0000000000..741e7554e8 --- /dev/null +++ b/crates/ruff/resources/test/fixtures/pyflakes/F811_22.py @@ -0,0 +1,13 @@ +def redef(value): + match value: + case True: + + def fun(x, y): + return x + + case False: + + def fun(x, y): + return y + + return fun \ No newline at end of file diff --git a/crates/ruff/src/rules/pyflakes/mod.rs b/crates/ruff/src/rules/pyflakes/mod.rs index 6df5ea86f3..a6b0196adb 100644 --- a/crates/ruff/src/rules/pyflakes/mod.rs +++ b/crates/ruff/src/rules/pyflakes/mod.rs @@ -96,6 +96,7 @@ mod tests { #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_19.py"); "F811_19")] #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_20.py"); "F811_20")] #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_21.py"); "F811_21")] + #[test_case(Rule::RedefinedWhileUnused, Path::new("F811_22.py"); "F811_22")] #[test_case(Rule::UndefinedName, Path::new("F821_0.py"); "F821_0")] #[test_case(Rule::UndefinedName, Path::new("F821_1.py"); "F821_1")] #[test_case(Rule::UndefinedName, Path::new("F821_2.py"); "F821_2")] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_22.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_22.py.snap new file mode 100644 index 0000000000..1976c4331d --- /dev/null +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_22.py.snap @@ -0,0 +1,4 @@ +--- +source: crates/ruff/src/rules/pyflakes/mod.rs +--- + diff --git a/crates/ruff_python_ast/src/branch_detection.rs b/crates/ruff_python_ast/src/branch_detection.rs index 42850452d9..2e3b2ced28 100644 --- a/crates/ruff_python_ast/src/branch_detection.rs +++ b/crates/ruff_python_ast/src/branch_detection.rs @@ -71,6 +71,10 @@ fn alternatives(stmt: RefEquality) -> Vec>> { body.iter().map(RefEquality).collect() })) .collect(), + StmtKind::Match { cases, .. } => cases + .iter() + .map(|case| case.body.iter().map(RefEquality).collect()) + .collect(), _ => vec![], } }