-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Fix missing undefined checks
#36599
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
Fix missing undefined checks
#36599
Conversation
|
@rbuckton please review, thanks! |
|
Updates: I've noticed that this bug can cause a memory leak, and restarting the typescript process frees up the RAM. Please let me know if there's anything I can do to help move this along. I understand that this is not a very visible (or critical) bug. Reply whenever you can. 😇 I really appreciate your taking the time to review. |
|
@sandersn The reason I didn't here: I'm not sure how to reproduce it consistently. I've tried. Latest Observations
I wish I had an easy reproduction, but these sorts of issues that only creep up after day(s) are hard to write steps for. Impact (low)
|
|
And I agree, I'd prefer to find the root cause too. 😸 I realize this is just moving the 'Null Exception' up the stack. I'm hopeful it'll lead to more helpful stack traces closer to where the issue actually resides. |
|
I don't know about #32851, but for #32864 I have a reproduction here: https://github.com/jscheid/typescript-32864 |
rbuckton
left a comment
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.
While I understand the desire to add these checks, this isn't the source of the problem. Rather, somewhere there is an unsound cast to a non-nullable type. I'd much rather find that root cause if possible as it is likely to cause other instabilities elsewhere.
| } | ||
|
|
||
| return node.emitNode; | ||
| return node && node.emitNode; |
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 shouldn't need this. We initialize the value if it isn't set two lines before this.
| */ | ||
| export function getSourceMapRange(node: Node): SourceMapRange { | ||
| const emitNode = node.emitNode; | ||
| const emitNode = node && node.emitNode; |
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.
If we're getting an error here its because we are somehow being passed a node that is undefined however we expect a defined 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.
Probably a symbol.valueDeclaration via some means, since that's a known hole in our current type definitions.
|
It seems the reason for this is that we return ...
checker.typeParameterToDeclaration(p, enclosingDeclaration) ??
createTypeParameterDeclaration('?')
... |
|
@justsml Do want to take on my proposed solution, or should I go ahead with a separate PR to fix this instead? |
|
Ah, I didn't see that. Yes, it looks like it does cover this case. |
|
@rbuckton And thanks @weswigham for solving the root cause. 😻 |
Fixes #32851
Fixes #32864
Added defensive null checks to prevent my VS Code's 'window logs' from filling up with
TypeScript Server Error (3.7.3)error messages every few minutes.Tasks
node.emitNodeinsrc/compiler/factoryPublic.tsUpdate: All tests pass.