Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1828,14 +1828,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
};

function runWithoutResolvedSignatureCaching<T>(node: Node | undefined, fn: () => T): T {
const containingCall = findAncestor(node, isCallLikeExpression);
const containingCallResolvedSignature = containingCall && getNodeLinks(containingCall).resolvedSignature;
if (containingCall) {
getNodeLinks(containingCall).resolvedSignature = undefined;
const cachedSignatures = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is important to do this for all signatures on the ancestry path because during completion requests diagnostics are not reported, this is reflected by const reportErrors = !isInferencePartiallyBlocked && !candidatesOutArray; in resolveCall. But if we only restore the result of the inner call (when doing a completion request within its argument) then we might cache the outer signature. That signature might even be correct - but what happens is that when actual diagnostics are requested we don't ever get to checking the inner call because a regular typecheck happens from the top to the bottom and the outer checkCallExpression could just use the cached signature and bail out from reaching the inner checkCallExpression

while (node) {
if (isCallLikeExpression(node)) {
const nodeLinks = getNodeLinks(node);
const resolvedSignature = nodeLinks.resolvedSignature;
cachedSignatures.push([nodeLinks, resolvedSignature] as const);
nodeLinks.resolvedSignature = undefined;
}
node = node.parent;
}
const result = fn();
if (containingCall) {
getNodeLinks(containingCall).resolvedSignature = containingCallResolvedSignature;
for (const [nodeLinks, resolvedSignature] of cachedSignatures) {
nodeLinks.resolvedSignature = resolvedSignature;
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
///<reference path="fourslash.ts"/>
// @strict: true
////
//// type GreetingEvent =
//// | { type: "MORNING" }
//// | { type: "LUNCH_TIME" }
//// | { type: "ALOHA" };
////
//// interface RaiseActionObject<TEvent extends { type: string }> {
//// type: "raise";
//// event: TEvent;
//// }
////
//// declare function raise<TEvent extends { type: string }>(
//// ev: TEvent
//// ): RaiseActionObject<TEvent>;
////
//// declare function createMachine<TEvent extends { type: string }>(config: {
//// actions: RaiseActionObject<TEvent>;
//// }): void;
////
//// createMachine<GreetingEvent>({
//// [|/*error*/actions|]: raise({ type: "ALOHA/*1*/" }),
//// });

goTo.marker("1");
edit.insert(`x`)
verify.completions({ exact: ["MORNING", "LUNCH_TIME", "ALOHA"] });
verify.getSemanticDiagnostics([{
code: 2322,
message: `Type 'RaiseActionObject<{ type: "ALOHAx"; }>' is not assignable to type 'RaiseActionObject<GreetingEvent>'.\n Type '{ type: "ALOHAx"; }' is not assignable to type 'GreetingEvent'.\n Type '{ type: "ALOHAx"; }' is not assignable to type '{ type: "ALOHA"; }'.\n Types of property 'type' are incompatible.\n Type '"ALOHAx"' is not assignable to type '"ALOHA"'.`,
}]);