initial revision of reachability checks#4788
Conversation
|
fancy 😎 |
src/compiler/binder.ts
Outdated
src/compiler/binder.ts
Outdated
There was a problem hiding this comment.
use the parameter name 'node' instead
src/compiler/binder.ts
Outdated
There was a problem hiding this comment.
I don't understand reachability of switch-statement. Why being exhaustive prevent post switch to be reachable?
|
🍺 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? |
|
@vladima function foo(x: number) {
if (x < 0) return 42;
} |
|
@DanielRosenwasser function foo(x: number): number {
if (x < 0) return 42;
} |
|
@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 |
|
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. 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 |
|
@ahejlsberg can you please check if your time measurements got better with last commit? |
src/compiler/binder.ts
Outdated
There was a problem hiding this comment.
Since we don't remove Debug.assert calls in retail code, this will always perform expensive number-to-string and string allocation/concatenation operations.
There was a problem hiding this comment.
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. |
|
👍 |
initial revision of reachability checks
…eScript#4788 (reachability checks)
|
What about the tsconfig.json schema? Shouldn't it be updated? |
this PR supersedes #1287.
Checking unreachable code in the compiler uncovered 2 bugs, both of the same origin:
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