Skip to content

bug: false positive of no-fallthrough for empty fallthrough in nested switch #1444

@xubaiwang

Description

@xubaiwang

Lint Name

no-fallthrough

Code Snippet

function booleanAnd(b1: boolean, b2: boolean) {
  switch (b1) {
    case true:        // false positive lint here
      switch (b2) {
        case true:
        default:
          return true;
      }
    case false:
      switch (b2) {
        case true:
          return true;
        case false:
          return false;
      }
  }
}

Expected Result

No linting errors.

Actual Result

❯ deno lint foo.ts 
error[no-fallthrough]: Fallthrough is not allowed
 --> /home/xubaiw/foo.ts:3:5
  | 
3 |     case true:
  |     ^^^^^^^^^^
  | 
4 |       switch (b2) {
  | ^^^^^^^^^^^^^^^^^^^
  | 
5 |         case true:
  | ^^^^^^^^^^^^^^^^^^
  | 
6 |         default:
  | ^^^^^^^^^^^^^^^^
  | 
7 |           return true;
  | ^^^^^^^^^^^^^^^^^^^^^^
  | 
8 |       }
  | ^^^^^^^
  = hint: Add `break` or comment `/* falls through */` to your case statement

  docs: https://docs.deno.com/lint/rules/no-fallthrough


Found 1 problem
Checked 1 file

Additional Info

This issue is different from #1331 , which is involved with End::Break, while this issue is about End::Continue.

Also reported in denoland/deno#29805 (closed now).

This problem may arise from here:

.filter_map(|case| self.get_end_reason(case.start()))
.try_fold(
End::Forced {
ret: false,
throw: false,
infinite_loop: false,
},
|acc, cur| acc.merge_forced(cur),
);

The fallthrough case is considered End::Continue, and fail to merge in merge_forced.

Version

deno 2.3.5 (stable, release, x86_64-unknown-linux-gnu)
v8 13.7.152.6-rusty
typescript 5.8.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions