From dbd866460d4973b04827132c9313b1c2381ca703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 12 Feb 2023 16:26:07 +0100 Subject: [PATCH] Do not report errors when inference is partially blocked --- src/compiler/checker.ts | 5 +++- ...ompletionsRequestWithinGenericFunction1.ts | 9 +++++++ ...ompletionsRequestWithinGenericFunction2.ts | 12 +++++++++ ...ompletionsRequestWithinGenericFunction3.ts | 25 +++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/noErrorsAfterCompletionsRequestWithinGenericFunction1.ts create mode 100644 tests/cases/fourslash/noErrorsAfterCompletionsRequestWithinGenericFunction2.ts create mode 100644 tests/cases/fourslash/noErrorsAfterCompletionsRequestWithinGenericFunction3.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 02ab562e00091..db143604ce54e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1423,6 +1423,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { let inlineLevel = 0; let currentNode: Node | undefined; let varianceTypeParameter: TypeParameter | undefined; + let isInferencePartiallyBlocked = false; const emptySymbols = createSymbolTable(); const arrayVariances = [VarianceFlags.Covariant]; @@ -1824,7 +1825,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } while (toMarkSkip && toMarkSkip !== containingCall); getNodeLinks(containingCall).resolvedSignature = undefined; } + isInferencePartiallyBlocked = true; const result = fn(); + isInferencePartiallyBlocked = false; if (containingCall) { let toMarkSkip = node!; do { @@ -32601,7 +32604,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const isTaggedTemplate = node.kind === SyntaxKind.TaggedTemplateExpression; const isDecorator = node.kind === SyntaxKind.Decorator; const isJsxOpeningOrSelfClosingElement = isJsxOpeningLikeElement(node); - const reportErrors = !candidatesOutArray; + const reportErrors = !isInferencePartiallyBlocked && !candidatesOutArray; let typeArguments: NodeArray | undefined; diff --git a/tests/cases/fourslash/noErrorsAfterCompletionsRequestWithinGenericFunction1.ts b/tests/cases/fourslash/noErrorsAfterCompletionsRequestWithinGenericFunction1.ts new file mode 100644 index 0000000000000..0ef19b43fcbd4 --- /dev/null +++ b/tests/cases/fourslash/noErrorsAfterCompletionsRequestWithinGenericFunction1.ts @@ -0,0 +1,9 @@ +/// +// @strict: true +//// +//// declare function func(arg: T): void; +//// func({ foo: 1, bar/*1*/: 1 }); + +goTo.marker("1"); +verify.completions({ exact: undefined }); +verify.noErrors(); diff --git a/tests/cases/fourslash/noErrorsAfterCompletionsRequestWithinGenericFunction2.ts b/tests/cases/fourslash/noErrorsAfterCompletionsRequestWithinGenericFunction2.ts new file mode 100644 index 0000000000000..6069ac397fdb7 --- /dev/null +++ b/tests/cases/fourslash/noErrorsAfterCompletionsRequestWithinGenericFunction2.ts @@ -0,0 +1,12 @@ +/// +// @strict: true +//// +//// // repro from #50818#issuecomment-1278324638 +//// +//// declare function func(arg: T): void; +//// func({ foo: 1, bar/*1*/: 1 }); + +goTo.marker("1"); +edit.insert("2"); +verify.completions({ exact: undefined }); +verify.noErrors(); diff --git a/tests/cases/fourslash/noErrorsAfterCompletionsRequestWithinGenericFunction3.ts b/tests/cases/fourslash/noErrorsAfterCompletionsRequestWithinGenericFunction3.ts new file mode 100644 index 0000000000000..11e8a819a3ebd --- /dev/null +++ b/tests/cases/fourslash/noErrorsAfterCompletionsRequestWithinGenericFunction3.ts @@ -0,0 +1,25 @@ +/// +// @strict: true +//// +//// // repro from #52580#issuecomment-1416131055 +//// +//// type Funcs> = { +//// [K in keyof B]: { +//// fn: (a: A, b: B) => void; +//// thing: B[K]; +//// } +//// } +//// +//// function foo>(fns: Funcs) {} +//// +//// foo({ +//// bar: { fn: (a: string, b) => {}, thing: "asd" }, +//// /*1*/ +//// }); + +goTo.marker("1"); +const markerPosition = test.markers()[0].position; +edit.paste(`bar: { fn: (a: string, b) => {}, thing: "asd" },`) +edit.replace(markerPosition + 4, 1, 'z') +verify.completions({ isNewIdentifierLocation: true }); +verify.noErrors();