Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing reachability error on non-const enum #58379

Open
weswigham opened this issue Apr 30, 2024 · 0 comments Β· May be fixed by #58380
Open

Missing reachability error on non-const enum #58379

weswigham opened this issue Apr 30, 2024 · 0 comments Β· May be fixed by #58380
Assignees
Labels
Bug A bug in TypeScript Domain: Control Flow The issue relates to control flow analysis

Comments

@weswigham
Copy link
Member

πŸ”Ž Search Terms

non-const enum unreachable error missing

πŸ•— Version & Regression Information

Nightly

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABAIwDYEMAWAKAlIgbwFgAoASHQDFwI8BuU0siBAZzlQFMA6VOAc2wAhdACduAQVwNyLMOy68B2MJwDuiSnDh5cTOQp59BIgF7cAbulQhO0xiSajOUEKLAymoSLASIqNHiETMxsHEbKIuJSMmSh8uFKgqoaWjq4euTxhknC6OZWNnaxAL4OZJxgIAC2iFGEiBKIZY6yGKysmtoNAB6IALyIAIwATADMACzN5WDo1ZysAA7oEJx1+Q2cPYtwolCIBvuFtgPD41MtJUA

πŸ’» Code

function blah() {
	aFunc();

	console.log(Bar.A);
	console.log(new Foo())
	console.log(Baz.value);


	return;

	function aFunc() {
		console.log(Bar.A);
		console.log(new Foo())
		console.log(Baz.value);
	}

	enum Bar { A }

	class Foo { x = 1234 }

	namespace Baz { export const value = 1234 }
}

πŸ™ Actual behavior

No error on Bar.

πŸ™‚ Expected behavior

Error on Bar - its' definition will never run.

Additional information about the issue

This is easy to accidentally cause in our own codebase, and esbuild actually covers up the problem by hoisting/inlining the enum - the problem only shows up in an unbundled build.

checkUnreachable in binder.ts is missing a check for EnumDeclarations (and a bail from that check for const enums).

@weswigham weswigham added Bug A bug in TypeScript Domain: Control Flow The issue relates to control flow analysis labels Apr 30, 2024
@jakebailey jakebailey linked a pull request Apr 30, 2024 that will close this issue
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 5.5.1 milestone May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Control Flow The issue relates to control flow analysis
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants