We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
this PR supersedes #1287. Checking unreachable code in the compiler uncovered 2 bugs, both of the same origin:
function foo() { return bar; / at this point x cannot be used yet because of TDZ let x: number; function bar() { if (!x) x = 0; return ++x; } }
Currently reachability checks are placed in binder but ultimately I'd like to be separate actions that are executed on the same pass - split walking and processing logic
Sorry, something went wrong.
initial revision of reachability checks in binder
b62ef0d
fancy 😎
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Space after switch
addressed PR feedback
beb1aa3
merge with master
9aeb0f8
use the parameter name 'node' instead
ok
682c14c
69321a0
I don't understand reachability of switch-statement. Why being exhaustive prevent post switch to be reachable?
discussed offline
🍪 🍰
4711f0e
🍺 is it enabled by default? impact on performance?
@ahejlsberg I've addressed your comments, can you please take another look to see if everything looks good from your perspective?
Merge branch 'master' into reachabilityChecks
7b12617
f9eaed7
@vladima noImplicitReturns doesn't seem to catch the following function:
noImplicitReturns
function foo(x: number) { if (x < 0) return 42; }
@DanielRosenwasser noImplicitReturns is enabled if return type is specified
function foo(x: number): number { if (x < 0) return 42; }
v2m@v2m-ThinkPad-W520:~/sources/TypeScript$ node built/local/tsc.js test.ts --noImplicitReturns test.ts(1,26): error TS7030: Not all code paths return a value.
@vladima yes, I wasn't sure if that was intentional or not. I think that's a little too subtle. I would assume you are more likely to forget a type annotation as you are an explicit return, and the switch is "no implicit returns".
currently implemented behavior is aligned with our existing approach to report errors on missing return or throw only if user explicitly opted in (by using return type annotation). However I do see how it might be subtle especially now it is kind of double opt-in (first via command line switch and second - by explicitly specifying return type) - this behavior can always be adjusted
return
throw
f96980d
This is fantastic! We love preventing bugs.
I'm curious if the team has discussed how to classify which static analysis will be included in the compiler, vs. what would be in something like tslint. Our experience at Google is that optional tooling is underused and much less effective. (we're writing a paper on it which I hope to share soon - cc @eaftan). As a trivial example, we found a handful of occurrences of a bug like:
if (condition); throw new IllegalState();
in Google's code, and this is very easily prevented by disallowing "empty" if statements with no then/else blocks.
Do you imagine adding many more compilerOptions like the new --noImplicitReturns added in this PR?
--noImplicitReturns
make binder singleton, inline bindWithReachabilityChecks
2779352
@ahejlsberg can you please check if your time measurements got better with last commit?
Since we don't remove Debug.assert calls in retail code, this will always perform expensive number-to-string and string allocation/concatenation operations.
Debug.assert
makes sense, will fix it
@vladima Just ran my RWC Monaco tests. With the latest changes we're now consistently a little bit faster than 1.6 even with reachability checks. Good stuff.
defer allocation of error message text in binder
7d09f26
d2a11b5
3f11c0b
👍
Merge pull request #4788 from Microsoft/reachabilityChecks
fb15e9c
initial revision of reachability checks
Added new tsconfig validation for options introduced in microsoft/Typ…
9b043c7
…eScript#4788 (reachability checks)
What about the tsconfig.json schema? Shouldn't it be updated?
Successfully merging this pull request may close these issues.