-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Make nonnull assertions and binding patterns apparent declared type locations #20995
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good once we have a better name for that function.
src/compiler/checker.ts
Outdated
} | ||
|
||
function typeHasNullableConstraint(type: Type) { | ||
return type.flags & TypeFlags.TypeVariable && maybeTypeOfKind(getBaseConstraintOfType(type) || emptyObjectType, TypeFlags.Nullable); | ||
} | ||
|
||
function getDeclaredOrApparentType(symbol: Symbol, node: Node) { | ||
function getDeclaredOrApparentType(type: Type, node: Node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a better name for this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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