-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fixed a ghost error popping up after completions request caching a wrong contextual function type #58378
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
base: main
Are you sure you want to change the base?
Conversation
…ong contextual function type
@@ -1923,32 +1923,42 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |||
} | |||
|
|||
function runWithoutResolvedSignatureCaching<T>(node: Node | undefined, fn: () => T): T { |
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.
This becomes more and more complicated and error-prone. I'm definitely not a fan of this. It builds on top of the existing solution... so at least it shouldn't be significantly worse now. It's just that perhaps there is a completely better way to do it than the existing mechanism. I think that alternatives could be explored separately.
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.
I thought about using infra introduced in #57421 but that PR is still in a draft. The problem space is also a little bit different - in this PR here we don't need to revert some recent work. In here, we need to temporarily evict some preexisting caches and restore them - we don't need to speculate per se. I assume that both are interested in the same lists of caches though.
const nodeLinks = getNodeLinks(node); | ||
cachedResolvedSignatures.push([nodeLinks, nodeLinks.resolvedSignature, nodeLinks.flags] as const); | ||
nodeLinks.resolvedSignature = undefined; | ||
nodeLinks.flags = NodeCheckFlags.None; |
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.
The key here is to reset NodeCheckFlags.ContextChecked
so contextuallyCheckFunctionExpressionOrObjectLiteralMethod
can correctly resolve (and cache) signature.resolvedReturnType
multiple times (for requests with inference blocked and for requests without inference blocked). Otherwise, it has to be resolved later on... but without proper contextual information.
So I could just remove that bit and re-add it later if needed. I looked through all NodeCheckFlags
and it might also be needed to do the same for NodeCheckFlags.TypeChecked
. Although, I'm not 100% sure if that's really the case.
I just tried with a complete flags reset here and it does seem to work... but 🤷♂️ I'd probably be in favor of resetting solely what's really-really needed.
fixes #58351