Make nonnull assertions and binding patterns apparent declared type locations#20995
Make nonnull assertions and binding patterns apparent declared type locations#20995weswigham merged 3 commits intomicrosoft:masterfrom
Conversation
|
Please explain what the issue is and how this fix solves it. |
|
In the process of doing control flow analysis for |
|
This seems to fix the problem, but I don't think it's fixing the actual problem, which is the "use before assignment" assertion on something that has been assigned. Regardless of what the type of (NOTE: I'm not very familiar with how the checking works internally, so I'm commenting based on the explanation above) |
|
@Kovensky the way that we do use before assignment checks in strict null checks mode is all about the type. You can only use before assignment a type without |
|
LGTM. @ahejlsberg any comments? |
… instead of getTypeWithFacts
|
@ahejlsberg This now uses the fix we talked about in person. |
ahejlsberg
left a comment
There was a problem hiding this comment.
Looks good once we have a better name for that function.
src/compiler/checker.ts
Outdated
| } | ||
|
|
||
| function getDeclaredOrApparentType(symbol: Symbol, node: Node) { | ||
| function getDeclaredOrApparentType(type: Type, node: Node) { |
There was a problem hiding this comment.
We need a better name for this method.
There was a problem hiding this comment.
Renamed to getApparentTypeForLocation
a062dc9 to
5dfffb1
Compare
|
@ahejlsberg done |
|
@weswigham I think @Kovensky is right that fixing the issue mentioned above could be achieved with a smaller change. |
* origin/master: (134 commits) Fix isTypeOfExpression in compiler API (microsoft#20875). (microsoft#20884) add completion filter for function like body (microsoft#21257) Make nonnull assertions and binding patterns apparent declared type locations (microsoft#20995) For `{ type: "a" } | { type: "b" }`, find references for the union property (microsoft#21298) configureNightly -> configurePrerelease Create a 'configure-insiders' and 'publish-insiders' task. Add createProgram on WatchCompilerHost in goToDefinition, use array helpers and clean up code (microsoft#21304) Support testing definition range of a reference gruop (microsoft#21302) Handle `undefined` input to firstDefined (microsoft#21300) Avoid spreading array (microsoft#21291) LEGO: check in for master to temporary branch. Accept new baselines Add regression test Properly handle contravariant inferences in inferReverseMappedType Remove unused properties from interface Refactor (microsoft#21286) LEGO: check in for master to temporary branch. Fold newline logic into getNewLineOrDefaultFromHost External test runner updates (microsoft#21276) Report more detailed info during script debug failure ...
|
@ajafff This also undoes an older bugfix which caused the issue in the first place, and instead fixes that bug differently. That's why the change is large. |
Fixes #20994