deno_lint icon indicating copy to clipboard operation
deno_lint copied to clipboard

Deno.exit() in switch statement yielts no-fallthrough warning without a break keyword

Open noxifoxi opened this issue 2 years ago • 3 comments

Lint Name

no-fallthrough

Code Snippet

switch (input) {
	case "x":
		Deno.exit();

	default:
		break;
}

Expected Result

No warnings about case fallthroughs

Actual Result

Warns about a fallthrough

Additional Info

deno-lint is not happy until I add break; after Deno.exit();, although it's unreachable: image

deno-ts(7027) knows and puts a notice about unreachable code: image

Version

VS-Code Extension: v3.12.0

deno 1.21.2 (release, x86_64-pc-windows-msvc) v8 10.0.139.17 typescript 4.6.2

noxifoxi avatar May 09 '22 22:05 noxifoxi

This is somewhat of a design limitation at this point... deno lint is not really aware that Deno.exit() has a return type of never. I wonder if we could handle that with @kdy1 control flow analysis?

CC @dsherret

bartlomieju avatar May 10 '22 09:05 bartlomieju

Using never type requires a good enough type checker

We can use a 'known list' of expression with never type alternatively

kdy1 avatar May 10 '22 09:05 kdy1

Using never type requires a good enough type checker

We can use a 'known list' of expression with never type alternatively

That's a good point, it's much simpler solution than incorporating type checking and should be good enough in this case.

bartlomieju avatar May 10 '22 09:05 bartlomieju