Skip to content

bug: incorrect assessment of unreachable code #1341

@flevi29

Description

@flevi29

Related #318

sometest.ts

let one: number | undefined;
mainLoop: for (;;) {
  let two: number | undefined;
  for (;;) {
    if (one === 10) {
      break mainLoop;
    }

    if (two === 10) {
      break;
    }

    two = (two ?? 0) + 1;
  }

  one = (one ?? 0) + 1;
  console.log(one);
}

console.log("fnished!");

deno .\sometest.ts

1
2
3
4
5
6
7
8
9
10
fnished!

deno lint .\sometest.ts

error[no-unreachable]: This statement is unreachable
  --> C:\Users\anon\search_state\sometest.ts:16:3
   |
16 |   one = (one ?? 0) + 1;
   |   ^^^^^^^^^^^^^^^^^^^^^

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


error[no-unreachable]: This statement is unreachable
  --> C:\Users\anon\search_state\sometest.ts:17:3
   |
17 |   console.log(one);
   |   ^^^^^^^^^^^^^^^^^

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


Found 2 problems
Checked 1 file

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions