From af0424c010076c325041d67e5c859ae5e168c62e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 1 Mar 2024 01:00:36 +0100 Subject: [PATCH] Fixed a crash when computing flow type of destructured never (#57586) --- src/compiler/checker.ts | 4 ++- ...ngDestructuringFromNeverNoCrash.errors.txt | 19 +++++++++++++ ...UsingDestructuringFromNeverNoCrash.symbols | 24 +++++++++++++++++ ...edUsingDestructuringFromNeverNoCrash.types | 27 +++++++++++++++++++ ...ignedUsingDestructuringFromNeverNoCrash.ts | 15 +++++++++++ 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/autoTypeAssignedUsingDestructuringFromNeverNoCrash.errors.txt create mode 100644 tests/baselines/reference/autoTypeAssignedUsingDestructuringFromNeverNoCrash.symbols create mode 100644 tests/baselines/reference/autoTypeAssignedUsingDestructuringFromNeverNoCrash.types create mode 100644 tests/cases/compiler/autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 27f9ed6f1b1..81dc893976c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -43214,7 +43214,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function getIteratedTypeOrElementType(use: IterationUse, inputType: Type, sentType: Type, errorNode: Node | undefined, checkAssignability: boolean): Type | undefined { const allowAsyncIterables = (use & IterationUse.AllowsAsyncIterablesFlag) !== 0; if (inputType === neverType) { - reportTypeNotIterableError(errorNode!, inputType, allowAsyncIterables); // TODO: GH#18217 + if (errorNode) { + reportTypeNotIterableError(errorNode, inputType, allowAsyncIterables); + } return undefined; } diff --git a/tests/baselines/reference/autoTypeAssignedUsingDestructuringFromNeverNoCrash.errors.txt b/tests/baselines/reference/autoTypeAssignedUsingDestructuringFromNeverNoCrash.errors.txt new file mode 100644 index 00000000000..e2a60126961 --- /dev/null +++ b/tests/baselines/reference/autoTypeAssignedUsingDestructuringFromNeverNoCrash.errors.txt @@ -0,0 +1,19 @@ +autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts(9,3): error TS2488: Type 'never' must have a '[Symbol.iterator]()' method that returns an iterator. + + +==== autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts (1 errors) ==== + // https://github.com/microsoft/TypeScript/issues/57582 + + declare const b: null; + let file; + + if (b === null) { + // empty + } else { + [file] = b; + ~~~~~~ +!!! error TS2488: Type 'never' must have a '[Symbol.iterator]()' method that returns an iterator. + } + + file; // request flow type here + \ No newline at end of file diff --git a/tests/baselines/reference/autoTypeAssignedUsingDestructuringFromNeverNoCrash.symbols b/tests/baselines/reference/autoTypeAssignedUsingDestructuringFromNeverNoCrash.symbols new file mode 100644 index 00000000000..4dd3e3d0bb9 --- /dev/null +++ b/tests/baselines/reference/autoTypeAssignedUsingDestructuringFromNeverNoCrash.symbols @@ -0,0 +1,24 @@ +//// [tests/cases/compiler/autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts] //// + +=== autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts === +// https://github.com/microsoft/TypeScript/issues/57582 + +declare const b: null; +>b : Symbol(b, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 2, 13)) + +let file; +>file : Symbol(file, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 3, 3)) + +if (b === null) { +>b : Symbol(b, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 2, 13)) + + // empty +} else { + [file] = b; +>file : Symbol(file, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 3, 3)) +>b : Symbol(b, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 2, 13)) +} + +file; // request flow type here +>file : Symbol(file, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 3, 3)) + diff --git a/tests/baselines/reference/autoTypeAssignedUsingDestructuringFromNeverNoCrash.types b/tests/baselines/reference/autoTypeAssignedUsingDestructuringFromNeverNoCrash.types new file mode 100644 index 00000000000..f540b98debb --- /dev/null +++ b/tests/baselines/reference/autoTypeAssignedUsingDestructuringFromNeverNoCrash.types @@ -0,0 +1,27 @@ +//// [tests/cases/compiler/autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts] //// + +=== autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts === +// https://github.com/microsoft/TypeScript/issues/57582 + +declare const b: null; +>b : null + +let file; +>file : any + +if (b === null) { +>b === null : boolean +>b : null + + // empty +} else { + [file] = b; +>[file] = b : never +>[file] : [any] +>file : any +>b : never +} + +file; // request flow type here +>file : any + diff --git a/tests/cases/compiler/autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts b/tests/cases/compiler/autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts new file mode 100644 index 00000000000..bb864cead0b --- /dev/null +++ b/tests/cases/compiler/autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts @@ -0,0 +1,15 @@ +// @strict: true +// @noEmit: true + +// https://github.com/microsoft/TypeScript/issues/57582 + +declare const b: null; +let file; + +if (b === null) { + // empty +} else { + [file] = b; +} + +file; // request flow type here