Skip to content

Commit c3d56c7

Browse files
committed
fix: nested switch fallthrough
1 parent 4a56a49 commit c3d56c7

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

src/control_flow/mod.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,13 +479,25 @@ impl Visit for Analyzer<'_> {
479479
.iter()
480480
.filter_map(|case| self.get_end_reason(case.start()))
481481
.try_fold(
482-
End::Forced {
483-
ret: false,
484-
throw: false,
485-
infinite_loop: false,
482+
(
483+
End::Forced {
484+
ret: false,
485+
throw: false,
486+
infinite_loop: false,
487+
},
488+
// record if previous is continue
489+
false,
490+
),
491+
|acc, cur| {
492+
if matches!(cur, End::Continue) {
493+
Some((acc.0, true))
494+
} else {
495+
acc.0.merge_forced(cur).map(|acc| (acc, false))
496+
}
486497
},
487-
|acc, cur| acc.merge_forced(cur),
488-
);
498+
)
499+
// None if last is continue
500+
.and_then(|(acc, last_continue)| (!last_continue).then_some(acc));
489501

490502
match forced_end {
491503
Some(e) if has_default => e,

src/rules/no_fallthrough.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,23 @@ switch(someValue) {
191191
console.log(42);
192192
}
193193
"#,
194+
r#"
195+
switch(foo) {
196+
case true:
197+
switch (bar) {
198+
case true:
199+
default:
200+
return true;
201+
}
202+
default:
203+
switch (bar) {
204+
case true:
205+
return true;
206+
default:
207+
return false;
208+
}
209+
}
210+
"#
194211
};
195212
}
196213

0 commit comments

Comments
 (0)