Skip to content

bug: false positive of no-fallthrough for break or continue inside nested switch inside loop  #1331

Open
@KnorpelSenf

Description

@KnorpelSenf

Lint Name

no-fallthrough

Code Snippet

export function repro(...nums: number[]) {
  for (let i = 0; i < nums.length; i++) {
    switch (nums[i]) {
      case 0:
        switch (i) {
          case 0:
            continue;
          default:
            return 0;
        }
      case 1:
        return 1;
    }
  }
}

Expected Result

No linting errors

Actual Result

$ deno lint
error[no-fallthrough]: Fallthrough is not allowed
  --> /tmp/repro/main.ts:4:7
   | 
 4 |       case 0:
   |       ^^^^^^^
   | 
 5 |         switch (i) {
   | ^^^^^^^^^^^^^^^^^^^^
   | 
 6 |           case 0:
   | ^^^^^^^^^^^^^^^^^
   | 
 7 |             continue;
   | ^^^^^^^^^^^^^^^^^^^^^
   | 
 8 |           default:
   | ^^^^^^^^^^^^^^^^^^
   | 
 9 |             return 0;
   | ^^^^^^^^^^^^^^^^^^^^^
   | 
10 |         }
   | ^^^^^^^^^
   = hint: Add `break` or comment `/* falls through */` to your case statement

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


Found 1 problem
Checked 1 file

Additional Info

The same problem can be observed when replacing continue by break.

Version

$ deno --version 
deno 1.46.3 (stable, release, x86_64-unknown-linux-gnu)
v8 12.9.202.5-rusty
typescript 5.5.2

This can also be seen with the RC of Deno 2.0.

$ deno --version 
deno 2.0.0-rc.4 (release candidate, release, x86_64-unknown-linux-gnu)
v8 12.9.202.13-rusty
typescript 5.6.2

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