From 97d69d442d78b30caef06101b27758d7d97c8e3f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 20 Sep 2019 17:18:08 -0700 Subject: [PATCH] Accept new baselines --- .../assertionTypePredicates1.errors.txt | 150 +++++ .../reference/assertionTypePredicates1.js | 289 +++++++++ .../assertionTypePredicates1.symbols | 359 +++++++++++ .../reference/assertionTypePredicates1.types | 438 +++++++++++++ ...ertionsAndNonReturningFunctions.errors.txt | 69 ++ ...assertionsAndNonReturningFunctions.symbols | 109 ++++ .../assertionsAndNonReturningFunctions.types | 152 +++++ .../exhaustiveSwitchImplicitReturn.errors.txt | 14 + .../exhaustiveSwitchImplicitReturn.js | 27 + .../exhaustiveSwitchImplicitReturn.symbols | 25 + .../exhaustiveSwitchImplicitReturn.types | 33 + .../exhaustiveSwitchStatements1.errors.txt | 202 ++++++ .../reference/exhaustiveSwitchStatements1.js | 437 +++++++++++++ .../exhaustiveSwitchStatements1.symbols | 503 +++++++++++++++ .../exhaustiveSwitchStatements1.types | 595 ++++++++++++++++++ .../neverReturningFunctions1.errors.txt | 227 +++++++ .../reference/neverReturningFunctions1.js | 337 ++++++++++ .../neverReturningFunctions1.symbols | 387 ++++++++++++ .../reference/neverReturningFunctions1.types | 439 +++++++++++++ 19 files changed, 4792 insertions(+) create mode 100644 tests/baselines/reference/assertionTypePredicates1.errors.txt create mode 100644 tests/baselines/reference/assertionTypePredicates1.js create mode 100644 tests/baselines/reference/assertionTypePredicates1.symbols create mode 100644 tests/baselines/reference/assertionTypePredicates1.types create mode 100644 tests/baselines/reference/assertionsAndNonReturningFunctions.errors.txt create mode 100644 tests/baselines/reference/assertionsAndNonReturningFunctions.symbols create mode 100644 tests/baselines/reference/assertionsAndNonReturningFunctions.types create mode 100644 tests/baselines/reference/exhaustiveSwitchStatements1.errors.txt create mode 100644 tests/baselines/reference/exhaustiveSwitchStatements1.js create mode 100644 tests/baselines/reference/exhaustiveSwitchStatements1.symbols create mode 100644 tests/baselines/reference/exhaustiveSwitchStatements1.types create mode 100644 tests/baselines/reference/neverReturningFunctions1.errors.txt create mode 100644 tests/baselines/reference/neverReturningFunctions1.js create mode 100644 tests/baselines/reference/neverReturningFunctions1.symbols create mode 100644 tests/baselines/reference/neverReturningFunctions1.types diff --git a/tests/baselines/reference/assertionTypePredicates1.errors.txt b/tests/baselines/reference/assertionTypePredicates1.errors.txt new file mode 100644 index 00000000000..91d2e869bd2 --- /dev/null +++ b/tests/baselines/reference/assertionTypePredicates1.errors.txt @@ -0,0 +1,150 @@ +tests/cases/conformance/controlFlow/assertionTypePredicates1.ts(116,37): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/controlFlow/assertionTypePredicates1.ts(117,37): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/controlFlow/assertionTypePredicates1.ts(118,37): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/controlFlow/assertionTypePredicates1.ts(121,15): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/controlFlow/assertionTypePredicates1.ts(122,15): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/controlFlow/assertionTypePredicates1.ts(123,15): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/controlFlow/assertionTypePredicates1.ts(124,15): error TS1228: A type predicate is only allowed in return type position for functions and methods. + + +==== tests/cases/conformance/controlFlow/assertionTypePredicates1.ts (7 errors) ==== + declare function isString(value: unknown): value is string; + declare function isArrayOfStrings(value: unknown): value is string[]; + + const assert: (value: unknown) => asserts value = value => {} + + declare function assertIsString(value: unknown): asserts value is string; + declare function assertIsArrayOfStrings(value: unknown): asserts value is string[]; + declare function assertDefined(value: T): asserts value is NonNullable; + + function f01(x: unknown) { + if (!!true) { + assert(typeof x === "string"); + x.length; + } + if (!!true) { + assert(x instanceof Error); + x.message; + } + if (!!true) { + assert(typeof x === "boolean" || typeof x === "number"); + x.toLocaleString; + } + if (!!true) { + assert(isArrayOfStrings(x)); + x[0].length; + } + if (!!true) { + assertIsArrayOfStrings(x); + x[0].length; + } + if (!!true) { + assert(x === undefined || typeof x === "string"); + x; // string | undefined + assertDefined(x); + x; // string + } + } + + function f02(x: string | undefined) { + if (!!true) { + assert(x); + x.length; + } + if (!!true) { + assert(x !== undefined); + x.length; + } + if (!!true) { + assertDefined(x); + x.length; + } + } + + function f03(x: string | undefined, assert: (value: unknown) => asserts value) { + assert(x); + x.length; + } + + namespace Debug { + export declare function assert(value: unknown, message?: string): asserts value; + export declare function assertDefined(value: T): asserts value is NonNullable; + } + + function f10(x: string | undefined) { + if (!!true) { + Debug.assert(x); + x.length; + } + if (!!true) { + Debug.assert(x !== undefined); + x.length; + } + if (!!true) { + Debug.assertDefined(x); + x.length; + } + } + + class Test { + assert(value: unknown): asserts value { + if (value) return; + throw new Error(); + } + isTest2(): this is Test2 { + return this instanceof Test2; + } + assertIsTest2(): asserts this is Test2 { + if (this instanceof Test2) return; + throw new Error(); + } + assertThis(): asserts this { + if (!this) return; + throw new Error(); + } + bar() { + this.assertThis(); + this; + } + foo(x: unknown) { + this.assert(typeof x === "string"); + x.length; + if (this.isTest2()) { + this.z; + } + this.assertIsTest2(); + this.z; + } + } + + class Test2 extends Test { + z = 0; + } + + // Invalid constructs + + declare let Q1: new (x: unknown) => x is string; + ~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. + declare let Q2: new (x: boolean) => asserts x; + ~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. + declare let Q3: new (x: unknown) => asserts x is string; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. + + declare class Wat { + get p1(): this is string; + ~~~~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. + set p1(x: this is string); + ~~~~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. + get p2(): asserts this is string; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. + set p2(x: asserts this is string); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. + } + \ No newline at end of file diff --git a/tests/baselines/reference/assertionTypePredicates1.js b/tests/baselines/reference/assertionTypePredicates1.js new file mode 100644 index 00000000000..ad21d116b73 --- /dev/null +++ b/tests/baselines/reference/assertionTypePredicates1.js @@ -0,0 +1,289 @@ +//// [assertionTypePredicates1.ts] +declare function isString(value: unknown): value is string; +declare function isArrayOfStrings(value: unknown): value is string[]; + +const assert: (value: unknown) => asserts value = value => {} + +declare function assertIsString(value: unknown): asserts value is string; +declare function assertIsArrayOfStrings(value: unknown): asserts value is string[]; +declare function assertDefined(value: T): asserts value is NonNullable; + +function f01(x: unknown) { + if (!!true) { + assert(typeof x === "string"); + x.length; + } + if (!!true) { + assert(x instanceof Error); + x.message; + } + if (!!true) { + assert(typeof x === "boolean" || typeof x === "number"); + x.toLocaleString; + } + if (!!true) { + assert(isArrayOfStrings(x)); + x[0].length; + } + if (!!true) { + assertIsArrayOfStrings(x); + x[0].length; + } + if (!!true) { + assert(x === undefined || typeof x === "string"); + x; // string | undefined + assertDefined(x); + x; // string + } +} + +function f02(x: string | undefined) { + if (!!true) { + assert(x); + x.length; + } + if (!!true) { + assert(x !== undefined); + x.length; + } + if (!!true) { + assertDefined(x); + x.length; + } +} + +function f03(x: string | undefined, assert: (value: unknown) => asserts value) { + assert(x); + x.length; +} + +namespace Debug { + export declare function assert(value: unknown, message?: string): asserts value; + export declare function assertDefined(value: T): asserts value is NonNullable; +} + +function f10(x: string | undefined) { + if (!!true) { + Debug.assert(x); + x.length; + } + if (!!true) { + Debug.assert(x !== undefined); + x.length; + } + if (!!true) { + Debug.assertDefined(x); + x.length; + } +} + +class Test { + assert(value: unknown): asserts value { + if (value) return; + throw new Error(); + } + isTest2(): this is Test2 { + return this instanceof Test2; + } + assertIsTest2(): asserts this is Test2 { + if (this instanceof Test2) return; + throw new Error(); + } + assertThis(): asserts this { + if (!this) return; + throw new Error(); + } + bar() { + this.assertThis(); + this; + } + foo(x: unknown) { + this.assert(typeof x === "string"); + x.length; + if (this.isTest2()) { + this.z; + } + this.assertIsTest2(); + this.z; + } +} + +class Test2 extends Test { + z = 0; +} + +// Invalid constructs + +declare let Q1: new (x: unknown) => x is string; +declare let Q2: new (x: boolean) => asserts x; +declare let Q3: new (x: unknown) => asserts x is string; + +declare class Wat { + get p1(): this is string; + set p1(x: this is string); + get p2(): asserts this is string; + set p2(x: asserts this is string); +} + + +//// [assertionTypePredicates1.js] +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var assert = function (value) { }; +function f01(x) { + if (!!true) { + assert(typeof x === "string"); + x.length; + } + if (!!true) { + assert(x instanceof Error); + x.message; + } + if (!!true) { + assert(typeof x === "boolean" || typeof x === "number"); + x.toLocaleString; + } + if (!!true) { + assert(isArrayOfStrings(x)); + x[0].length; + } + if (!!true) { + assertIsArrayOfStrings(x); + x[0].length; + } + if (!!true) { + assert(x === undefined || typeof x === "string"); + x; // string | undefined + assertDefined(x); + x; // string + } +} +function f02(x) { + if (!!true) { + assert(x); + x.length; + } + if (!!true) { + assert(x !== undefined); + x.length; + } + if (!!true) { + assertDefined(x); + x.length; + } +} +function f03(x, assert) { + assert(x); + x.length; +} +var Debug; +(function (Debug) { +})(Debug || (Debug = {})); +function f10(x) { + if (!!true) { + Debug.assert(x); + x.length; + } + if (!!true) { + Debug.assert(x !== undefined); + x.length; + } + if (!!true) { + Debug.assertDefined(x); + x.length; + } +} +var Test = /** @class */ (function () { + function Test() { + } + Test.prototype.assert = function (value) { + if (value) + return; + throw new Error(); + }; + Test.prototype.isTest2 = function () { + return this instanceof Test2; + }; + Test.prototype.assertIsTest2 = function () { + if (this instanceof Test2) + return; + throw new Error(); + }; + Test.prototype.assertThis = function () { + if (!this) + return; + throw new Error(); + }; + Test.prototype.bar = function () { + this.assertThis(); + this; + }; + Test.prototype.foo = function (x) { + this.assert(typeof x === "string"); + x.length; + if (this.isTest2()) { + this.z; + } + this.assertIsTest2(); + this.z; + }; + return Test; +}()); +var Test2 = /** @class */ (function (_super) { + __extends(Test2, _super); + function Test2() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.z = 0; + return _this; + } + return Test2; +}(Test)); + + +//// [assertionTypePredicates1.d.ts] +declare function isString(value: unknown): value is string; +declare function isArrayOfStrings(value: unknown): value is string[]; +declare const assert: (value: unknown) => asserts value; +declare function assertIsString(value: unknown): asserts value is string; +declare function assertIsArrayOfStrings(value: unknown): asserts value is string[]; +declare function assertDefined(value: T): asserts value is NonNullable; +declare function f01(x: unknown): void; +declare function f02(x: string | undefined): void; +declare function f03(x: string | undefined, assert: (value: unknown) => asserts value): void; +declare namespace Debug { + function assert(value: unknown, message?: string): asserts value; + function assertDefined(value: T): asserts value is NonNullable; +} +declare function f10(x: string | undefined): void; +declare class Test { + assert(value: unknown): asserts value; + isTest2(): this is Test2; + assertIsTest2(): asserts this is Test2; + assertThis(): asserts this; + bar(): void; + foo(x: unknown): void; +} +declare class Test2 extends Test { + z: number; +} +declare let Q1: new (x: unknown) => x is string; +declare let Q2: new (x: boolean) => asserts x; +declare let Q3: new (x: unknown) => asserts x is string; +declare class Wat { + get p1(): this is string; + set p1(x: this is string); + get p2(): asserts this is string; + set p2(x: asserts this is string); +} diff --git a/tests/baselines/reference/assertionTypePredicates1.symbols b/tests/baselines/reference/assertionTypePredicates1.symbols new file mode 100644 index 00000000000..c68a1926aff --- /dev/null +++ b/tests/baselines/reference/assertionTypePredicates1.symbols @@ -0,0 +1,359 @@ +=== tests/cases/conformance/controlFlow/assertionTypePredicates1.ts === +declare function isString(value: unknown): value is string; +>isString : Symbol(isString, Decl(assertionTypePredicates1.ts, 0, 0)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 0, 26)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 0, 26)) + +declare function isArrayOfStrings(value: unknown): value is string[]; +>isArrayOfStrings : Symbol(isArrayOfStrings, Decl(assertionTypePredicates1.ts, 0, 59)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 1, 34)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 1, 34)) + +const assert: (value: unknown) => asserts value = value => {} +>assert : Symbol(assert, Decl(assertionTypePredicates1.ts, 3, 5)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 3, 15)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 3, 15)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 3, 49)) + +declare function assertIsString(value: unknown): asserts value is string; +>assertIsString : Symbol(assertIsString, Decl(assertionTypePredicates1.ts, 3, 61)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 5, 32)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 5, 32)) + +declare function assertIsArrayOfStrings(value: unknown): asserts value is string[]; +>assertIsArrayOfStrings : Symbol(assertIsArrayOfStrings, Decl(assertionTypePredicates1.ts, 5, 73)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 6, 40)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 6, 40)) + +declare function assertDefined(value: T): asserts value is NonNullable; +>assertDefined : Symbol(assertDefined, Decl(assertionTypePredicates1.ts, 6, 83)) +>T : Symbol(T, Decl(assertionTypePredicates1.ts, 7, 31)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 7, 34)) +>T : Symbol(T, Decl(assertionTypePredicates1.ts, 7, 31)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 7, 34)) +>NonNullable : Symbol(NonNullable, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(assertionTypePredicates1.ts, 7, 31)) + +function f01(x: unknown) { +>f01 : Symbol(f01, Decl(assertionTypePredicates1.ts, 7, 77)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 9, 13)) + + if (!!true) { + assert(typeof x === "string"); +>assert : Symbol(assert, Decl(assertionTypePredicates1.ts, 3, 5)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 9, 13)) + + x.length; +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 9, 13)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + } + if (!!true) { + assert(x instanceof Error); +>assert : Symbol(assert, Decl(assertionTypePredicates1.ts, 3, 5)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 9, 13)) +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + + x.message; +>x.message : Symbol(Error.message, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 9, 13)) +>message : Symbol(Error.message, Decl(lib.es5.d.ts, --, --)) + } + if (!!true) { + assert(typeof x === "boolean" || typeof x === "number"); +>assert : Symbol(assert, Decl(assertionTypePredicates1.ts, 3, 5)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 9, 13)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 9, 13)) + + x.toLocaleString; +>x.toLocaleString : Symbol(toLocaleString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 9, 13)) +>toLocaleString : Symbol(toLocaleString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + } + if (!!true) { + assert(isArrayOfStrings(x)); +>assert : Symbol(assert, Decl(assertionTypePredicates1.ts, 3, 5)) +>isArrayOfStrings : Symbol(isArrayOfStrings, Decl(assertionTypePredicates1.ts, 0, 59)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 9, 13)) + + x[0].length; +>x[0].length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 9, 13)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + } + if (!!true) { + assertIsArrayOfStrings(x); +>assertIsArrayOfStrings : Symbol(assertIsArrayOfStrings, Decl(assertionTypePredicates1.ts, 5, 73)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 9, 13)) + + x[0].length; +>x[0].length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 9, 13)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + } + if (!!true) { + assert(x === undefined || typeof x === "string"); +>assert : Symbol(assert, Decl(assertionTypePredicates1.ts, 3, 5)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 9, 13)) +>undefined : Symbol(undefined) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 9, 13)) + + x; // string | undefined +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 9, 13)) + + assertDefined(x); +>assertDefined : Symbol(assertDefined, Decl(assertionTypePredicates1.ts, 6, 83)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 9, 13)) + + x; // string +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 9, 13)) + } +} + +function f02(x: string | undefined) { +>f02 : Symbol(f02, Decl(assertionTypePredicates1.ts, 36, 1)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 38, 13)) + + if (!!true) { + assert(x); +>assert : Symbol(assert, Decl(assertionTypePredicates1.ts, 3, 5)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 38, 13)) + + x.length; +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 38, 13)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + } + if (!!true) { + assert(x !== undefined); +>assert : Symbol(assert, Decl(assertionTypePredicates1.ts, 3, 5)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 38, 13)) +>undefined : Symbol(undefined) + + x.length; +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 38, 13)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + } + if (!!true) { + assertDefined(x); +>assertDefined : Symbol(assertDefined, Decl(assertionTypePredicates1.ts, 6, 83)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 38, 13)) + + x.length; +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 38, 13)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + } +} + +function f03(x: string | undefined, assert: (value: unknown) => asserts value) { +>f03 : Symbol(f03, Decl(assertionTypePredicates1.ts, 51, 1)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 53, 13)) +>assert : Symbol(assert, Decl(assertionTypePredicates1.ts, 53, 35)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 53, 45)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 53, 45)) + + assert(x); +>assert : Symbol(assert, Decl(assertionTypePredicates1.ts, 53, 35)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 53, 13)) + + x.length; +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 53, 13)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +} + +namespace Debug { +>Debug : Symbol(Debug, Decl(assertionTypePredicates1.ts, 56, 1)) + + export declare function assert(value: unknown, message?: string): asserts value; +>assert : Symbol(assert, Decl(assertionTypePredicates1.ts, 58, 17)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 59, 35)) +>message : Symbol(message, Decl(assertionTypePredicates1.ts, 59, 50)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 59, 35)) + + export declare function assertDefined(value: T): asserts value is NonNullable; +>assertDefined : Symbol(assertDefined, Decl(assertionTypePredicates1.ts, 59, 84)) +>T : Symbol(T, Decl(assertionTypePredicates1.ts, 60, 42)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 60, 45)) +>T : Symbol(T, Decl(assertionTypePredicates1.ts, 60, 42)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 60, 45)) +>NonNullable : Symbol(NonNullable, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(assertionTypePredicates1.ts, 60, 42)) +} + +function f10(x: string | undefined) { +>f10 : Symbol(f10, Decl(assertionTypePredicates1.ts, 61, 1)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 63, 13)) + + if (!!true) { + Debug.assert(x); +>Debug.assert : Symbol(Debug.assert, Decl(assertionTypePredicates1.ts, 58, 17)) +>Debug : Symbol(Debug, Decl(assertionTypePredicates1.ts, 56, 1)) +>assert : Symbol(Debug.assert, Decl(assertionTypePredicates1.ts, 58, 17)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 63, 13)) + + x.length; +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 63, 13)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + } + if (!!true) { + Debug.assert(x !== undefined); +>Debug.assert : Symbol(Debug.assert, Decl(assertionTypePredicates1.ts, 58, 17)) +>Debug : Symbol(Debug, Decl(assertionTypePredicates1.ts, 56, 1)) +>assert : Symbol(Debug.assert, Decl(assertionTypePredicates1.ts, 58, 17)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 63, 13)) +>undefined : Symbol(undefined) + + x.length; +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 63, 13)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + } + if (!!true) { + Debug.assertDefined(x); +>Debug.assertDefined : Symbol(Debug.assertDefined, Decl(assertionTypePredicates1.ts, 59, 84)) +>Debug : Symbol(Debug, Decl(assertionTypePredicates1.ts, 56, 1)) +>assertDefined : Symbol(Debug.assertDefined, Decl(assertionTypePredicates1.ts, 59, 84)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 63, 13)) + + x.length; +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 63, 13)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + } +} + +class Test { +>Test : Symbol(Test, Decl(assertionTypePredicates1.ts, 76, 1)) + + assert(value: unknown): asserts value { +>assert : Symbol(Test.assert, Decl(assertionTypePredicates1.ts, 78, 12)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 79, 11)) +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 79, 11)) + + if (value) return; +>value : Symbol(value, Decl(assertionTypePredicates1.ts, 79, 11)) + + throw new Error(); +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + } + isTest2(): this is Test2 { +>isTest2 : Symbol(Test.isTest2, Decl(assertionTypePredicates1.ts, 82, 5)) +>Test2 : Symbol(Test2, Decl(assertionTypePredicates1.ts, 107, 1)) + + return this instanceof Test2; +>this : Symbol(Test, Decl(assertionTypePredicates1.ts, 76, 1)) +>Test2 : Symbol(Test2, Decl(assertionTypePredicates1.ts, 107, 1)) + } + assertIsTest2(): asserts this is Test2 { +>assertIsTest2 : Symbol(Test.assertIsTest2, Decl(assertionTypePredicates1.ts, 85, 5)) +>Test2 : Symbol(Test2, Decl(assertionTypePredicates1.ts, 107, 1)) + + if (this instanceof Test2) return; +>this : Symbol(Test, Decl(assertionTypePredicates1.ts, 76, 1)) +>Test2 : Symbol(Test2, Decl(assertionTypePredicates1.ts, 107, 1)) + + throw new Error(); +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + } + assertThis(): asserts this { +>assertThis : Symbol(Test.assertThis, Decl(assertionTypePredicates1.ts, 89, 5)) + + if (!this) return; +>this : Symbol(Test, Decl(assertionTypePredicates1.ts, 76, 1)) + + throw new Error(); +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + } + bar() { +>bar : Symbol(Test.bar, Decl(assertionTypePredicates1.ts, 93, 5)) + + this.assertThis(); +>this.assertThis : Symbol(Test.assertThis, Decl(assertionTypePredicates1.ts, 89, 5)) +>this : Symbol(Test, Decl(assertionTypePredicates1.ts, 76, 1)) +>assertThis : Symbol(Test.assertThis, Decl(assertionTypePredicates1.ts, 89, 5)) + + this; +>this : Symbol(Test, Decl(assertionTypePredicates1.ts, 76, 1)) + } + foo(x: unknown) { +>foo : Symbol(Test.foo, Decl(assertionTypePredicates1.ts, 97, 5)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 98, 8)) + + this.assert(typeof x === "string"); +>this.assert : Symbol(Test.assert, Decl(assertionTypePredicates1.ts, 78, 12)) +>this : Symbol(Test, Decl(assertionTypePredicates1.ts, 76, 1)) +>assert : Symbol(Test.assert, Decl(assertionTypePredicates1.ts, 78, 12)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 98, 8)) + + x.length; +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 98, 8)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + + if (this.isTest2()) { +>this.isTest2 : Symbol(Test.isTest2, Decl(assertionTypePredicates1.ts, 82, 5)) +>this : Symbol(Test, Decl(assertionTypePredicates1.ts, 76, 1)) +>isTest2 : Symbol(Test.isTest2, Decl(assertionTypePredicates1.ts, 82, 5)) + + this.z; +>this.z : Symbol(Test2.z, Decl(assertionTypePredicates1.ts, 109, 26)) +>z : Symbol(Test2.z, Decl(assertionTypePredicates1.ts, 109, 26)) + } + this.assertIsTest2(); +>this.assertIsTest2 : Symbol(Test.assertIsTest2, Decl(assertionTypePredicates1.ts, 85, 5)) +>this : Symbol(Test, Decl(assertionTypePredicates1.ts, 76, 1)) +>assertIsTest2 : Symbol(Test.assertIsTest2, Decl(assertionTypePredicates1.ts, 85, 5)) + + this.z; +>this.z : Symbol(Test2.z, Decl(assertionTypePredicates1.ts, 109, 26)) +>z : Symbol(Test2.z, Decl(assertionTypePredicates1.ts, 109, 26)) + } +} + +class Test2 extends Test { +>Test2 : Symbol(Test2, Decl(assertionTypePredicates1.ts, 107, 1)) +>Test : Symbol(Test, Decl(assertionTypePredicates1.ts, 76, 1)) + + z = 0; +>z : Symbol(Test2.z, Decl(assertionTypePredicates1.ts, 109, 26)) +} + +// Invalid constructs + +declare let Q1: new (x: unknown) => x is string; +>Q1 : Symbol(Q1, Decl(assertionTypePredicates1.ts, 115, 11)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 115, 21)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 115, 21)) + +declare let Q2: new (x: boolean) => asserts x; +>Q2 : Symbol(Q2, Decl(assertionTypePredicates1.ts, 116, 11)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 116, 21)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 116, 21)) + +declare let Q3: new (x: unknown) => asserts x is string; +>Q3 : Symbol(Q3, Decl(assertionTypePredicates1.ts, 117, 11)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 117, 21)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 117, 21)) + +declare class Wat { +>Wat : Symbol(Wat, Decl(assertionTypePredicates1.ts, 117, 56)) + + get p1(): this is string; +>p1 : Symbol(Wat.p1, Decl(assertionTypePredicates1.ts, 119, 19), Decl(assertionTypePredicates1.ts, 120, 29)) + + set p1(x: this is string); +>p1 : Symbol(Wat.p1, Decl(assertionTypePredicates1.ts, 119, 19), Decl(assertionTypePredicates1.ts, 120, 29)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 121, 11)) + + get p2(): asserts this is string; +>p2 : Symbol(Wat.p2, Decl(assertionTypePredicates1.ts, 121, 30), Decl(assertionTypePredicates1.ts, 122, 37)) + + set p2(x: asserts this is string); +>p2 : Symbol(Wat.p2, Decl(assertionTypePredicates1.ts, 121, 30), Decl(assertionTypePredicates1.ts, 122, 37)) +>x : Symbol(x, Decl(assertionTypePredicates1.ts, 123, 11)) +} + diff --git a/tests/baselines/reference/assertionTypePredicates1.types b/tests/baselines/reference/assertionTypePredicates1.types new file mode 100644 index 00000000000..f72ec641013 --- /dev/null +++ b/tests/baselines/reference/assertionTypePredicates1.types @@ -0,0 +1,438 @@ +=== tests/cases/conformance/controlFlow/assertionTypePredicates1.ts === +declare function isString(value: unknown): value is string; +>isString : (value: unknown) => value is string +>value : unknown + +declare function isArrayOfStrings(value: unknown): value is string[]; +>isArrayOfStrings : (value: unknown) => value is string[] +>value : unknown + +const assert: (value: unknown) => asserts value = value => {} +>assert : (value: unknown) => asserts value +>value : unknown +>value => {} : (value: unknown) => void +>value : unknown + +declare function assertIsString(value: unknown): asserts value is string; +>assertIsString : (value: unknown) => asserts value is string +>value : unknown + +declare function assertIsArrayOfStrings(value: unknown): asserts value is string[]; +>assertIsArrayOfStrings : (value: unknown) => asserts value is string[] +>value : unknown + +declare function assertDefined(value: T): asserts value is NonNullable; +>assertDefined : (value: T) => asserts value is NonNullable +>value : T + +function f01(x: unknown) { +>f01 : (x: unknown) => void +>x : unknown + + if (!!true) { +>!!true : true +>!true : false +>true : true + + assert(typeof x === "string"); +>assert(typeof x === "string") : void +>assert : (value: unknown) => asserts value +>typeof x === "string" : boolean +>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>x : unknown +>"string" : "string" + + x.length; +>x.length : number +>x : string +>length : number + } + if (!!true) { +>!!true : true +>!true : false +>true : true + + assert(x instanceof Error); +>assert(x instanceof Error) : void +>assert : (value: unknown) => asserts value +>x instanceof Error : boolean +>x : unknown +>Error : ErrorConstructor + + x.message; +>x.message : string +>x : Error +>message : string + } + if (!!true) { +>!!true : true +>!true : false +>true : true + + assert(typeof x === "boolean" || typeof x === "number"); +>assert(typeof x === "boolean" || typeof x === "number") : void +>assert : (value: unknown) => asserts value +>typeof x === "boolean" || typeof x === "number" : boolean +>typeof x === "boolean" : boolean +>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>x : unknown +>"boolean" : "boolean" +>typeof x === "number" : boolean +>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>x : unknown +>"number" : "number" + + x.toLocaleString; +>x.toLocaleString : ((locales?: string | string[] | undefined, options?: Intl.NumberFormatOptions | undefined) => string) | (() => string) +>x : number | boolean +>toLocaleString : ((locales?: string | string[] | undefined, options?: Intl.NumberFormatOptions | undefined) => string) | (() => string) + } + if (!!true) { +>!!true : true +>!true : false +>true : true + + assert(isArrayOfStrings(x)); +>assert(isArrayOfStrings(x)) : void +>assert : (value: unknown) => asserts value +>isArrayOfStrings(x) : boolean +>isArrayOfStrings : (value: unknown) => value is string[] +>x : unknown + + x[0].length; +>x[0].length : number +>x[0] : string +>x : string[] +>0 : 0 +>length : number + } + if (!!true) { +>!!true : true +>!true : false +>true : true + + assertIsArrayOfStrings(x); +>assertIsArrayOfStrings(x) : void +>assertIsArrayOfStrings : (value: unknown) => asserts value is string[] +>x : unknown + + x[0].length; +>x[0].length : number +>x[0] : string +>x : string[] +>0 : 0 +>length : number + } + if (!!true) { +>!!true : true +>!true : false +>true : true + + assert(x === undefined || typeof x === "string"); +>assert(x === undefined || typeof x === "string") : void +>assert : (value: unknown) => asserts value +>x === undefined || typeof x === "string" : boolean +>x === undefined : boolean +>x : unknown +>undefined : undefined +>typeof x === "string" : boolean +>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>x : unknown +>"string" : "string" + + x; // string | undefined +>x : string | undefined + + assertDefined(x); +>assertDefined(x) : void +>assertDefined : (value: T) => asserts value is NonNullable +>x : string | undefined + + x; // string +>x : string + } +} + +function f02(x: string | undefined) { +>f02 : (x: string | undefined) => void +>x : string | undefined + + if (!!true) { +>!!true : true +>!true : false +>true : true + + assert(x); +>assert(x) : void +>assert : (value: unknown) => asserts value +>x : string | undefined + + x.length; +>x.length : number +>x : string +>length : number + } + if (!!true) { +>!!true : true +>!true : false +>true : true + + assert(x !== undefined); +>assert(x !== undefined) : void +>assert : (value: unknown) => asserts value +>x !== undefined : boolean +>x : string | undefined +>undefined : undefined + + x.length; +>x.length : number +>x : string +>length : number + } + if (!!true) { +>!!true : true +>!true : false +>true : true + + assertDefined(x); +>assertDefined(x) : void +>assertDefined : (value: T) => asserts value is NonNullable +>x : string | undefined + + x.length; +>x.length : number +>x : string +>length : number + } +} + +function f03(x: string | undefined, assert: (value: unknown) => asserts value) { +>f03 : (x: string | undefined, assert: (value: unknown) => asserts value) => void +>x : string | undefined +>assert : (value: unknown) => asserts value +>value : unknown + + assert(x); +>assert(x) : void +>assert : (value: unknown) => asserts value +>x : string | undefined + + x.length; +>x.length : number +>x : string +>length : number +} + +namespace Debug { +>Debug : typeof Debug + + export declare function assert(value: unknown, message?: string): asserts value; +>assert : (value: unknown, message?: string | undefined) => asserts value +>value : unknown +>message : string | undefined + + export declare function assertDefined(value: T): asserts value is NonNullable; +>assertDefined : (value: T) => asserts value is NonNullable +>value : T +} + +function f10(x: string | undefined) { +>f10 : (x: string | undefined) => void +>x : string | undefined + + if (!!true) { +>!!true : true +>!true : false +>true : true + + Debug.assert(x); +>Debug.assert(x) : void +>Debug.assert : (value: unknown, message?: string | undefined) => asserts value +>Debug : typeof Debug +>assert : (value: unknown, message?: string | undefined) => asserts value +>x : string | undefined + + x.length; +>x.length : number +>x : string +>length : number + } + if (!!true) { +>!!true : true +>!true : false +>true : true + + Debug.assert(x !== undefined); +>Debug.assert(x !== undefined) : void +>Debug.assert : (value: unknown, message?: string | undefined) => asserts value +>Debug : typeof Debug +>assert : (value: unknown, message?: string | undefined) => asserts value +>x !== undefined : boolean +>x : string | undefined +>undefined : undefined + + x.length; +>x.length : number +>x : string +>length : number + } + if (!!true) { +>!!true : true +>!true : false +>true : true + + Debug.assertDefined(x); +>Debug.assertDefined(x) : void +>Debug.assertDefined : (value: T) => asserts value is NonNullable +>Debug : typeof Debug +>assertDefined : (value: T) => asserts value is NonNullable +>x : string | undefined + + x.length; +>x.length : number +>x : string +>length : number + } +} + +class Test { +>Test : Test + + assert(value: unknown): asserts value { +>assert : (value: unknown) => asserts value +>value : unknown + + if (value) return; +>value : unknown + + throw new Error(); +>new Error() : Error +>Error : ErrorConstructor + } + isTest2(): this is Test2 { +>isTest2 : () => this is Test2 + + return this instanceof Test2; +>this instanceof Test2 : boolean +>this : this +>Test2 : typeof Test2 + } + assertIsTest2(): asserts this is Test2 { +>assertIsTest2 : () => asserts this is Test2 + + if (this instanceof Test2) return; +>this instanceof Test2 : boolean +>this : this +>Test2 : typeof Test2 + + throw new Error(); +>new Error() : Error +>Error : ErrorConstructor + } + assertThis(): asserts this { +>assertThis : () => asserts this + + if (!this) return; +>!this : false +>this : this + + throw new Error(); +>new Error() : Error +>Error : ErrorConstructor + } + bar() { +>bar : () => void + + this.assertThis(); +>this.assertThis() : void +>this.assertThis : () => asserts this +>this : this +>assertThis : () => asserts this + + this; +>this : this + } + foo(x: unknown) { +>foo : (x: unknown) => void +>x : unknown + + this.assert(typeof x === "string"); +>this.assert(typeof x === "string") : void +>this.assert : (value: unknown) => asserts value +>this : this +>assert : (value: unknown) => asserts value +>typeof x === "string" : boolean +>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>x : unknown +>"string" : "string" + + x.length; +>x.length : number +>x : string +>length : number + + if (this.isTest2()) { +>this.isTest2() : boolean +>this.isTest2 : () => this is Test2 +>this : this +>isTest2 : () => this is Test2 + + this.z; +>this.z : number +>this : this & Test2 +>z : number + } + this.assertIsTest2(); +>this.assertIsTest2() : void +>this.assertIsTest2 : () => asserts this is Test2 +>this : this +>assertIsTest2 : () => asserts this is Test2 + + this.z; +>this.z : number +>this : this & Test2 +>z : number + } +} + +class Test2 extends Test { +>Test2 : Test2 +>Test : Test + + z = 0; +>z : number +>0 : 0 +} + +// Invalid constructs + +declare let Q1: new (x: unknown) => x is string; +>Q1 : new (x: unknown) => x is string +>x : unknown + +declare let Q2: new (x: boolean) => asserts x; +>Q2 : new (x: boolean) => asserts x +>x : boolean + +declare let Q3: new (x: unknown) => asserts x is string; +>Q3 : new (x: unknown) => asserts x is string +>x : unknown + +declare class Wat { +>Wat : Wat + + get p1(): this is string; +>p1 : boolean + + set p1(x: this is string); +>p1 : boolean +>x : boolean + + get p2(): asserts this is string; +>p2 : void + + set p2(x: asserts this is string); +>p2 : void +>x : void +} + diff --git a/tests/baselines/reference/assertionsAndNonReturningFunctions.errors.txt b/tests/baselines/reference/assertionsAndNonReturningFunctions.errors.txt new file mode 100644 index 00000000000..e1648d7643d --- /dev/null +++ b/tests/baselines/reference/assertionsAndNonReturningFunctions.errors.txt @@ -0,0 +1,69 @@ +tests/cases/conformance/jsdoc/assertionsAndNonReturningFunctions.js(46,9): error TS7027: Unreachable code detected. +tests/cases/conformance/jsdoc/assertionsAndNonReturningFunctions.js(58,5): error TS7027: Unreachable code detected. + + +==== tests/cases/conformance/jsdoc/assertionsAndNonReturningFunctions.js (2 errors) ==== + /** @typedef {(check: boolean) => asserts check} AssertFunc */ + + /** @type {AssertFunc} */ + const assert = check => { + if (!check) throw new Error(); + } + + /** @type {(x: unknown) => asserts x is string } */ + function assertIsString(x) { + if (!(typeof x === "string")) throw new Error(); + } + + /** + * @param {boolean} check + * @returns {asserts check} + */ + function assert2(check) { + if (!check) throw new Error(); + } + + /** + * @returns {never} + */ + function fail() { + throw new Error(); + } + + /** + * @param {*} x + */ + function f1(x) { + if (!!true) { + assert(typeof x === "string"); + x.length; + } + if (!!true) { + assert2(typeof x === "string"); + x.length; + } + if (!!true) { + assertIsString(x); + x.length; + } + if (!!true) { + fail(); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + } + + /** + * @param {boolean} b + */ + function f2(b) { + switch (b) { + case true: return 1; + case false: return 0; + } + b; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + \ No newline at end of file diff --git a/tests/baselines/reference/assertionsAndNonReturningFunctions.symbols b/tests/baselines/reference/assertionsAndNonReturningFunctions.symbols new file mode 100644 index 00000000000..88931cffbd8 --- /dev/null +++ b/tests/baselines/reference/assertionsAndNonReturningFunctions.symbols @@ -0,0 +1,109 @@ +=== tests/cases/conformance/jsdoc/assertionsAndNonReturningFunctions.js === +/** @typedef {(check: boolean) => asserts check} AssertFunc */ + +/** @type {AssertFunc} */ +const assert = check => { +>assert : Symbol(assert, Decl(assertionsAndNonReturningFunctions.js, 3, 5)) +>check : Symbol(check, Decl(assertionsAndNonReturningFunctions.js, 3, 14)) + + if (!check) throw new Error(); +>check : Symbol(check, Decl(assertionsAndNonReturningFunctions.js, 3, 14)) +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +} + +/** @type {(x: unknown) => asserts x is string } */ +function assertIsString(x) { +>assertIsString : Symbol(assertIsString, Decl(assertionsAndNonReturningFunctions.js, 5, 1)) +>x : Symbol(x, Decl(assertionsAndNonReturningFunctions.js, 8, 24)) + + if (!(typeof x === "string")) throw new Error(); +>x : Symbol(x, Decl(assertionsAndNonReturningFunctions.js, 8, 24)) +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +} + +/** + * @param {boolean} check + * @returns {asserts check} +*/ +function assert2(check) { +>assert2 : Symbol(assert2, Decl(assertionsAndNonReturningFunctions.js, 10, 1)) +>check : Symbol(check, Decl(assertionsAndNonReturningFunctions.js, 16, 17)) + + if (!check) throw new Error(); +>check : Symbol(check, Decl(assertionsAndNonReturningFunctions.js, 16, 17)) +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +} + +/** + * @returns {never} + */ +function fail() { +>fail : Symbol(fail, Decl(assertionsAndNonReturningFunctions.js, 18, 1)) + + throw new Error(); +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +} + +/** + * @param {*} x + */ +function f1(x) { +>f1 : Symbol(f1, Decl(assertionsAndNonReturningFunctions.js, 25, 1)) +>x : Symbol(x, Decl(assertionsAndNonReturningFunctions.js, 30, 12)) + + if (!!true) { + assert(typeof x === "string"); +>assert : Symbol(assert, Decl(assertionsAndNonReturningFunctions.js, 3, 5)) +>x : Symbol(x, Decl(assertionsAndNonReturningFunctions.js, 30, 12)) + + x.length; +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(assertionsAndNonReturningFunctions.js, 30, 12)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + } + if (!!true) { + assert2(typeof x === "string"); +>assert2 : Symbol(assert2, Decl(assertionsAndNonReturningFunctions.js, 10, 1)) +>x : Symbol(x, Decl(assertionsAndNonReturningFunctions.js, 30, 12)) + + x.length; +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(assertionsAndNonReturningFunctions.js, 30, 12)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + } + if (!!true) { + assertIsString(x); +>assertIsString : Symbol(assertIsString, Decl(assertionsAndNonReturningFunctions.js, 5, 1)) +>x : Symbol(x, Decl(assertionsAndNonReturningFunctions.js, 30, 12)) + + x.length; +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(assertionsAndNonReturningFunctions.js, 30, 12)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + } + if (!!true) { + fail(); +>fail : Symbol(fail, Decl(assertionsAndNonReturningFunctions.js, 18, 1)) + + x; // Unreachable +>x : Symbol(x, Decl(assertionsAndNonReturningFunctions.js, 30, 12)) + } +} + +/** + * @param {boolean} b + */ +function f2(b) { +>f2 : Symbol(f2, Decl(assertionsAndNonReturningFunctions.js, 47, 1)) +>b : Symbol(b, Decl(assertionsAndNonReturningFunctions.js, 52, 12)) + + switch (b) { +>b : Symbol(b, Decl(assertionsAndNonReturningFunctions.js, 52, 12)) + + case true: return 1; + case false: return 0; + } + b; // Unreachable +>b : Symbol(b, Decl(assertionsAndNonReturningFunctions.js, 52, 12)) +} + diff --git a/tests/baselines/reference/assertionsAndNonReturningFunctions.types b/tests/baselines/reference/assertionsAndNonReturningFunctions.types new file mode 100644 index 00000000000..32100b6c3d2 --- /dev/null +++ b/tests/baselines/reference/assertionsAndNonReturningFunctions.types @@ -0,0 +1,152 @@ +=== tests/cases/conformance/jsdoc/assertionsAndNonReturningFunctions.js === +/** @typedef {(check: boolean) => asserts check} AssertFunc */ + +/** @type {AssertFunc} */ +const assert = check => { +>assert : (check: boolean) => asserts check +>check => { if (!check) throw new Error();} : (check: boolean) => asserts check +>check : boolean + + if (!check) throw new Error(); +>!check : boolean +>check : boolean +>new Error() : Error +>Error : ErrorConstructor +} + +/** @type {(x: unknown) => asserts x is string } */ +function assertIsString(x) { +>assertIsString : (x: unknown) => asserts x is string +>x : unknown + + if (!(typeof x === "string")) throw new Error(); +>!(typeof x === "string") : boolean +>(typeof x === "string") : boolean +>typeof x === "string" : boolean +>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>x : unknown +>"string" : "string" +>new Error() : Error +>Error : ErrorConstructor +} + +/** + * @param {boolean} check + * @returns {asserts check} +*/ +function assert2(check) { +>assert2 : (check: boolean) => asserts check +>check : boolean + + if (!check) throw new Error(); +>!check : boolean +>check : boolean +>new Error() : Error +>Error : ErrorConstructor +} + +/** + * @returns {never} + */ +function fail() { +>fail : () => never + + throw new Error(); +>new Error() : Error +>Error : ErrorConstructor +} + +/** + * @param {*} x + */ +function f1(x) { +>f1 : (x: any) => void +>x : any + + if (!!true) { +>!!true : boolean +>!true : boolean +>true : true + + assert(typeof x === "string"); +>assert(typeof x === "string") : void +>assert : (check: boolean) => asserts check +>typeof x === "string" : boolean +>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>x : any +>"string" : "string" + + x.length; +>x.length : number +>x : string +>length : number + } + if (!!true) { +>!!true : boolean +>!true : boolean +>true : true + + assert2(typeof x === "string"); +>assert2(typeof x === "string") : void +>assert2 : (check: boolean) => asserts check +>typeof x === "string" : boolean +>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>x : any +>"string" : "string" + + x.length; +>x.length : number +>x : string +>length : number + } + if (!!true) { +>!!true : boolean +>!true : boolean +>true : true + + assertIsString(x); +>assertIsString(x) : void +>assertIsString : (x: unknown) => asserts x is string +>x : any + + x.length; +>x.length : number +>x : string +>length : number + } + if (!!true) { +>!!true : boolean +>!true : boolean +>true : true + + fail(); +>fail() : never +>fail : () => never + + x; // Unreachable +>x : any + } +} + +/** + * @param {boolean} b + */ +function f2(b) { +>f2 : (b: boolean) => 1 | 0 +>b : boolean + + switch (b) { +>b : boolean + + case true: return 1; +>true : true +>1 : 1 + + case false: return 0; +>false : false +>0 : 0 + } + b; // Unreachable +>b : never +} + diff --git a/tests/baselines/reference/exhaustiveSwitchImplicitReturn.errors.txt b/tests/baselines/reference/exhaustiveSwitchImplicitReturn.errors.txt index 43b5467f0d2..89daa42c268 100644 --- a/tests/baselines/reference/exhaustiveSwitchImplicitReturn.errors.txt +++ b/tests/baselines/reference/exhaustiveSwitchImplicitReturn.errors.txt @@ -44,4 +44,18 @@ tests/cases/compiler/exhaustiveSwitchImplicitReturn.ts(35,32): error TS7030: Not return 1; } } + + function foo6(bar: "a", a: boolean, b: boolean): number { + if (a) { + switch (bar) { + case "a": return 1; + } + } + else { + switch (b) { + case true: return -1; + case false: return 0; + } + } + } \ No newline at end of file diff --git a/tests/baselines/reference/exhaustiveSwitchImplicitReturn.js b/tests/baselines/reference/exhaustiveSwitchImplicitReturn.js index 5f8bf348c5f..9877f251993 100644 --- a/tests/baselines/reference/exhaustiveSwitchImplicitReturn.js +++ b/tests/baselines/reference/exhaustiveSwitchImplicitReturn.js @@ -39,6 +39,20 @@ function foo5(bar: "a" | "b"): number { return 1; } } + +function foo6(bar: "a", a: boolean, b: boolean): number { + if (a) { + switch (bar) { + case "a": return 1; + } + } + else { + switch (b) { + case true: return -1; + case false: return 0; + } + } +} //// [exhaustiveSwitchImplicitReturn.js] @@ -75,3 +89,16 @@ function foo5(bar) { return 1; } } +function foo6(bar, a, b) { + if (a) { + switch (bar) { + case "a": return 1; + } + } + else { + switch (b) { + case true: return -1; + case false: return 0; + } + } +} diff --git a/tests/baselines/reference/exhaustiveSwitchImplicitReturn.symbols b/tests/baselines/reference/exhaustiveSwitchImplicitReturn.symbols index d93a5228362..dcad190a9b3 100644 --- a/tests/baselines/reference/exhaustiveSwitchImplicitReturn.symbols +++ b/tests/baselines/reference/exhaustiveSwitchImplicitReturn.symbols @@ -69,3 +69,28 @@ function foo5(bar: "a" | "b"): number { } } +function foo6(bar: "a", a: boolean, b: boolean): number { +>foo6 : Symbol(foo6, Decl(exhaustiveSwitchImplicitReturn.ts, 39, 1)) +>bar : Symbol(bar, Decl(exhaustiveSwitchImplicitReturn.ts, 41, 14)) +>a : Symbol(a, Decl(exhaustiveSwitchImplicitReturn.ts, 41, 23)) +>b : Symbol(b, Decl(exhaustiveSwitchImplicitReturn.ts, 41, 35)) + + if (a) { +>a : Symbol(a, Decl(exhaustiveSwitchImplicitReturn.ts, 41, 23)) + + switch (bar) { +>bar : Symbol(bar, Decl(exhaustiveSwitchImplicitReturn.ts, 41, 14)) + + case "a": return 1; + } + } + else { + switch (b) { +>b : Symbol(b, Decl(exhaustiveSwitchImplicitReturn.ts, 41, 35)) + + case true: return -1; + case false: return 0; + } + } +} + diff --git a/tests/baselines/reference/exhaustiveSwitchImplicitReturn.types b/tests/baselines/reference/exhaustiveSwitchImplicitReturn.types index c868aa99b8f..c72b3b24477 100644 --- a/tests/baselines/reference/exhaustiveSwitchImplicitReturn.types +++ b/tests/baselines/reference/exhaustiveSwitchImplicitReturn.types @@ -85,3 +85,36 @@ function foo5(bar: "a" | "b"): number { } } +function foo6(bar: "a", a: boolean, b: boolean): number { +>foo6 : (bar: "a", a: boolean, b: boolean) => number +>bar : "a" +>a : boolean +>b : boolean + + if (a) { +>a : boolean + + switch (bar) { +>bar : "a" + + case "a": return 1; +>"a" : "a" +>1 : 1 + } + } + else { + switch (b) { +>b : boolean + + case true: return -1; +>true : true +>-1 : -1 +>1 : 1 + + case false: return 0; +>false : false +>0 : 0 + } + } +} + diff --git a/tests/baselines/reference/exhaustiveSwitchStatements1.errors.txt b/tests/baselines/reference/exhaustiveSwitchStatements1.errors.txt new file mode 100644 index 00000000000..4a54518413d --- /dev/null +++ b/tests/baselines/reference/exhaustiveSwitchStatements1.errors.txt @@ -0,0 +1,202 @@ +tests/cases/conformance/controlFlow/exhaustiveSwitchStatements1.ts(7,9): error TS7027: Unreachable code detected. + + +==== tests/cases/conformance/controlFlow/exhaustiveSwitchStatements1.ts (1 errors) ==== + function f1(x: 1 | 2): string { + if (!!true) { + switch (x) { + case 1: return 'a'; + case 2: return 'b'; + } + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + else { + throw 0; + } + } + + function f2(x: 1 | 2) { + let z: number; + switch (x) { + case 1: z = 10; break; + case 2: z = 20; break; + } + z; // Definitely assigned + } + + function f3(x: 1 | 2) { + switch (x) { + case 1: return 10; + case 2: return 20; + // Default considered reachable to allow defensive coding + default: throw new Error("Bad input"); + } + } + + // Repro from #11572 + + enum E { A, B } + + function f(e: E): number { + switch (e) { + case E.A: return 0 + case E.B: return 1 + } + } + + function g(e: E): number { + if (!true) + return -1 + else + switch (e) { + case E.A: return 0 + case E.B: return 1 + } + } + + // Repro from #12668 + + interface Square { kind: "square"; size: number; } + + interface Rectangle { kind: "rectangle"; width: number; height: number; } + + interface Circle { kind: "circle"; radius: number; } + + interface Triangle { kind: "triangle"; side: number; } + + type Shape = Square | Rectangle | Circle | Triangle; + + function area(s: Shape): number { + let area; + switch (s.kind) { + case "square": area = s.size * s.size; break; + case "rectangle": area = s.width * s.height; break; + case "circle": area = Math.PI * s.radius * s.radius; break; + case "triangle": area = Math.sqrt(3) / 4 * s.side * s.side; break; + } + return area; + } + + function areaWrapped(s: Shape): number { + let area; + area = (() => { + switch (s.kind) { + case "square": return s.size * s.size; + case "rectangle": return s.width * s.height; + case "circle": return Math.PI * s.radius * s.radius; + case "triangle": return Math.sqrt(3) / 4 * s.side * s.side; + } + })(); + return area; + } + + // Repro from #13241 + + enum MyEnum { + A, + B + } + + function thisGivesError(e: MyEnum): string { + let s: string; + switch (e) { + case MyEnum.A: s = "it was A"; break; + case MyEnum.B: s = "it was B"; break; + } + return s; + } + + function good1(e: MyEnum): string { + let s: string; + switch (e) { + case MyEnum.A: s = "it was A"; break; + case MyEnum.B: s = "it was B"; break; + default: s = "it was something else"; break; + } + return s; + } + + function good2(e: MyEnum): string { + switch (e) { + case MyEnum.A: return "it was A"; + case MyEnum.B: return "it was B"; + } + } + + // Repro from #18362 + + enum Level { + One, + Two, + } + + const doSomethingWithLevel = (level: Level) => { + let next: Level; + switch (level) { + case Level.One: + next = Level.Two; + break; + case Level.Two: + next = Level.One; + break; + } + return next; + }; + + // Repro from #20409 + + interface Square2 { + kind: "square"; + size: number; + } + + interface Circle2 { + kind: "circle"; + radius: number; + } + + type Shape2 = Square2 | Circle2; + + function withDefault(s1: Shape2, s2: Shape2): string { + switch (s1.kind) { + case "square": + return "1"; + case "circle": + switch (s2.kind) { + case "square": + return "2"; + case "circle": + return "3"; + default: + return "never"; + } + } + } + + function withoutDefault(s1: Shape2, s2: Shape2): string { + switch (s1.kind) { + case "square": + return "1"; + case "circle": + switch (s2.kind) { + case "square": + return "2"; + case "circle": + return "3"; + } + } + } + + // Repro from #20823 + + function test4(value: 1 | 2) { + let x: string; + switch (value) { + case 1: x = "one"; break; + case 2: x = "two"; break; + } + return x; + } + \ No newline at end of file diff --git a/tests/baselines/reference/exhaustiveSwitchStatements1.js b/tests/baselines/reference/exhaustiveSwitchStatements1.js new file mode 100644 index 00000000000..a39db3b8101 --- /dev/null +++ b/tests/baselines/reference/exhaustiveSwitchStatements1.js @@ -0,0 +1,437 @@ +//// [exhaustiveSwitchStatements1.ts] +function f1(x: 1 | 2): string { + if (!!true) { + switch (x) { + case 1: return 'a'; + case 2: return 'b'; + } + x; // Unreachable + } + else { + throw 0; + } +} + +function f2(x: 1 | 2) { + let z: number; + switch (x) { + case 1: z = 10; break; + case 2: z = 20; break; + } + z; // Definitely assigned +} + +function f3(x: 1 | 2) { + switch (x) { + case 1: return 10; + case 2: return 20; + // Default considered reachable to allow defensive coding + default: throw new Error("Bad input"); + } +} + +// Repro from #11572 + +enum E { A, B } + +function f(e: E): number { + switch (e) { + case E.A: return 0 + case E.B: return 1 + } +} + +function g(e: E): number { + if (!true) + return -1 + else + switch (e) { + case E.A: return 0 + case E.B: return 1 + } +} + +// Repro from #12668 + +interface Square { kind: "square"; size: number; } + +interface Rectangle { kind: "rectangle"; width: number; height: number; } + +interface Circle { kind: "circle"; radius: number; } + +interface Triangle { kind: "triangle"; side: number; } + +type Shape = Square | Rectangle | Circle | Triangle; + +function area(s: Shape): number { + let area; + switch (s.kind) { + case "square": area = s.size * s.size; break; + case "rectangle": area = s.width * s.height; break; + case "circle": area = Math.PI * s.radius * s.radius; break; + case "triangle": area = Math.sqrt(3) / 4 * s.side * s.side; break; + } + return area; +} + +function areaWrapped(s: Shape): number { + let area; + area = (() => { + switch (s.kind) { + case "square": return s.size * s.size; + case "rectangle": return s.width * s.height; + case "circle": return Math.PI * s.radius * s.radius; + case "triangle": return Math.sqrt(3) / 4 * s.side * s.side; + } + })(); + return area; +} + +// Repro from #13241 + +enum MyEnum { + A, + B +} + +function thisGivesError(e: MyEnum): string { + let s: string; + switch (e) { + case MyEnum.A: s = "it was A"; break; + case MyEnum.B: s = "it was B"; break; + } + return s; +} + +function good1(e: MyEnum): string { + let s: string; + switch (e) { + case MyEnum.A: s = "it was A"; break; + case MyEnum.B: s = "it was B"; break; + default: s = "it was something else"; break; + } + return s; +} + +function good2(e: MyEnum): string { + switch (e) { + case MyEnum.A: return "it was A"; + case MyEnum.B: return "it was B"; + } +} + +// Repro from #18362 + +enum Level { + One, + Two, +} + +const doSomethingWithLevel = (level: Level) => { + let next: Level; + switch (level) { + case Level.One: + next = Level.Two; + break; + case Level.Two: + next = Level.One; + break; + } + return next; +}; + +// Repro from #20409 + +interface Square2 { + kind: "square"; + size: number; +} + +interface Circle2 { + kind: "circle"; + radius: number; +} + +type Shape2 = Square2 | Circle2; + +function withDefault(s1: Shape2, s2: Shape2): string { + switch (s1.kind) { + case "square": + return "1"; + case "circle": + switch (s2.kind) { + case "square": + return "2"; + case "circle": + return "3"; + default: + return "never"; + } + } +} + +function withoutDefault(s1: Shape2, s2: Shape2): string { + switch (s1.kind) { + case "square": + return "1"; + case "circle": + switch (s2.kind) { + case "square": + return "2"; + case "circle": + return "3"; + } + } +} + +// Repro from #20823 + +function test4(value: 1 | 2) { + let x: string; + switch (value) { + case 1: x = "one"; break; + case 2: x = "two"; break; + } + return x; +} + + +//// [exhaustiveSwitchStatements1.js] +"use strict"; +function f1(x) { + if (!!true) { + switch (x) { + case 1: return 'a'; + case 2: return 'b'; + } + x; // Unreachable + } + else { + throw 0; + } +} +function f2(x) { + var z; + switch (x) { + case 1: + z = 10; + break; + case 2: + z = 20; + break; + } + z; // Definitely assigned +} +function f3(x) { + switch (x) { + case 1: return 10; + case 2: return 20; + // Default considered reachable to allow defensive coding + default: throw new Error("Bad input"); + } +} +// Repro from #11572 +var E; +(function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; +})(E || (E = {})); +function f(e) { + switch (e) { + case E.A: return 0; + case E.B: return 1; + } +} +function g(e) { + if (!true) + return -1; + else + switch (e) { + case E.A: return 0; + case E.B: return 1; + } +} +function area(s) { + var area; + switch (s.kind) { + case "square": + area = s.size * s.size; + break; + case "rectangle": + area = s.width * s.height; + break; + case "circle": + area = Math.PI * s.radius * s.radius; + break; + case "triangle": + area = Math.sqrt(3) / 4 * s.side * s.side; + break; + } + return area; +} +function areaWrapped(s) { + var area; + area = (function () { + switch (s.kind) { + case "square": return s.size * s.size; + case "rectangle": return s.width * s.height; + case "circle": return Math.PI * s.radius * s.radius; + case "triangle": return Math.sqrt(3) / 4 * s.side * s.side; + } + })(); + return area; +} +// Repro from #13241 +var MyEnum; +(function (MyEnum) { + MyEnum[MyEnum["A"] = 0] = "A"; + MyEnum[MyEnum["B"] = 1] = "B"; +})(MyEnum || (MyEnum = {})); +function thisGivesError(e) { + var s; + switch (e) { + case MyEnum.A: + s = "it was A"; + break; + case MyEnum.B: + s = "it was B"; + break; + } + return s; +} +function good1(e) { + var s; + switch (e) { + case MyEnum.A: + s = "it was A"; + break; + case MyEnum.B: + s = "it was B"; + break; + default: + s = "it was something else"; + break; + } + return s; +} +function good2(e) { + switch (e) { + case MyEnum.A: return "it was A"; + case MyEnum.B: return "it was B"; + } +} +// Repro from #18362 +var Level; +(function (Level) { + Level[Level["One"] = 0] = "One"; + Level[Level["Two"] = 1] = "Two"; +})(Level || (Level = {})); +var doSomethingWithLevel = function (level) { + var next; + switch (level) { + case Level.One: + next = Level.Two; + break; + case Level.Two: + next = Level.One; + break; + } + return next; +}; +function withDefault(s1, s2) { + switch (s1.kind) { + case "square": + return "1"; + case "circle": + switch (s2.kind) { + case "square": + return "2"; + case "circle": + return "3"; + default: + return "never"; + } + } +} +function withoutDefault(s1, s2) { + switch (s1.kind) { + case "square": + return "1"; + case "circle": + switch (s2.kind) { + case "square": + return "2"; + case "circle": + return "3"; + } + } +} +// Repro from #20823 +function test4(value) { + var x; + switch (value) { + case 1: + x = "one"; + break; + case 2: + x = "two"; + break; + } + return x; +} + + +//// [exhaustiveSwitchStatements1.d.ts] +declare function f1(x: 1 | 2): string; +declare function f2(x: 1 | 2): void; +declare function f3(x: 1 | 2): 10 | 20; +declare enum E { + A = 0, + B = 1 +} +declare function f(e: E): number; +declare function g(e: E): number; +interface Square { + kind: "square"; + size: number; +} +interface Rectangle { + kind: "rectangle"; + width: number; + height: number; +} +interface Circle { + kind: "circle"; + radius: number; +} +interface Triangle { + kind: "triangle"; + side: number; +} +declare type Shape = Square | Rectangle | Circle | Triangle; +declare function area(s: Shape): number; +declare function areaWrapped(s: Shape): number; +declare enum MyEnum { + A = 0, + B = 1 +} +declare function thisGivesError(e: MyEnum): string; +declare function good1(e: MyEnum): string; +declare function good2(e: MyEnum): string; +declare enum Level { + One = 0, + Two = 1 +} +declare const doSomethingWithLevel: (level: Level) => Level; +interface Square2 { + kind: "square"; + size: number; +} +interface Circle2 { + kind: "circle"; + radius: number; +} +declare type Shape2 = Square2 | Circle2; +declare function withDefault(s1: Shape2, s2: Shape2): string; +declare function withoutDefault(s1: Shape2, s2: Shape2): string; +declare function test4(value: 1 | 2): string; diff --git a/tests/baselines/reference/exhaustiveSwitchStatements1.symbols b/tests/baselines/reference/exhaustiveSwitchStatements1.symbols new file mode 100644 index 00000000000..8beb3911883 --- /dev/null +++ b/tests/baselines/reference/exhaustiveSwitchStatements1.symbols @@ -0,0 +1,503 @@ +=== tests/cases/conformance/controlFlow/exhaustiveSwitchStatements1.ts === +function f1(x: 1 | 2): string { +>f1 : Symbol(f1, Decl(exhaustiveSwitchStatements1.ts, 0, 0)) +>x : Symbol(x, Decl(exhaustiveSwitchStatements1.ts, 0, 12)) + + if (!!true) { + switch (x) { +>x : Symbol(x, Decl(exhaustiveSwitchStatements1.ts, 0, 12)) + + case 1: return 'a'; + case 2: return 'b'; + } + x; // Unreachable +>x : Symbol(x, Decl(exhaustiveSwitchStatements1.ts, 0, 12)) + } + else { + throw 0; + } +} + +function f2(x: 1 | 2) { +>f2 : Symbol(f2, Decl(exhaustiveSwitchStatements1.ts, 11, 1)) +>x : Symbol(x, Decl(exhaustiveSwitchStatements1.ts, 13, 12)) + + let z: number; +>z : Symbol(z, Decl(exhaustiveSwitchStatements1.ts, 14, 7)) + + switch (x) { +>x : Symbol(x, Decl(exhaustiveSwitchStatements1.ts, 13, 12)) + + case 1: z = 10; break; +>z : Symbol(z, Decl(exhaustiveSwitchStatements1.ts, 14, 7)) + + case 2: z = 20; break; +>z : Symbol(z, Decl(exhaustiveSwitchStatements1.ts, 14, 7)) + } + z; // Definitely assigned +>z : Symbol(z, Decl(exhaustiveSwitchStatements1.ts, 14, 7)) +} + +function f3(x: 1 | 2) { +>f3 : Symbol(f3, Decl(exhaustiveSwitchStatements1.ts, 20, 1)) +>x : Symbol(x, Decl(exhaustiveSwitchStatements1.ts, 22, 12)) + + switch (x) { +>x : Symbol(x, Decl(exhaustiveSwitchStatements1.ts, 22, 12)) + + case 1: return 10; + case 2: return 20; + // Default considered reachable to allow defensive coding + default: throw new Error("Bad input"); +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + } +} + +// Repro from #11572 + +enum E { A, B } +>E : Symbol(E, Decl(exhaustiveSwitchStatements1.ts, 29, 1)) +>A : Symbol(E.A, Decl(exhaustiveSwitchStatements1.ts, 33, 8)) +>B : Symbol(E.B, Decl(exhaustiveSwitchStatements1.ts, 33, 11)) + +function f(e: E): number { +>f : Symbol(f, Decl(exhaustiveSwitchStatements1.ts, 33, 15)) +>e : Symbol(e, Decl(exhaustiveSwitchStatements1.ts, 35, 11)) +>E : Symbol(E, Decl(exhaustiveSwitchStatements1.ts, 29, 1)) + + switch (e) { +>e : Symbol(e, Decl(exhaustiveSwitchStatements1.ts, 35, 11)) + + case E.A: return 0 +>E.A : Symbol(E.A, Decl(exhaustiveSwitchStatements1.ts, 33, 8)) +>E : Symbol(E, Decl(exhaustiveSwitchStatements1.ts, 29, 1)) +>A : Symbol(E.A, Decl(exhaustiveSwitchStatements1.ts, 33, 8)) + + case E.B: return 1 +>E.B : Symbol(E.B, Decl(exhaustiveSwitchStatements1.ts, 33, 11)) +>E : Symbol(E, Decl(exhaustiveSwitchStatements1.ts, 29, 1)) +>B : Symbol(E.B, Decl(exhaustiveSwitchStatements1.ts, 33, 11)) + } +} + +function g(e: E): number { +>g : Symbol(g, Decl(exhaustiveSwitchStatements1.ts, 40, 1)) +>e : Symbol(e, Decl(exhaustiveSwitchStatements1.ts, 42, 11)) +>E : Symbol(E, Decl(exhaustiveSwitchStatements1.ts, 29, 1)) + + if (!true) + return -1 + else + switch (e) { +>e : Symbol(e, Decl(exhaustiveSwitchStatements1.ts, 42, 11)) + + case E.A: return 0 +>E.A : Symbol(E.A, Decl(exhaustiveSwitchStatements1.ts, 33, 8)) +>E : Symbol(E, Decl(exhaustiveSwitchStatements1.ts, 29, 1)) +>A : Symbol(E.A, Decl(exhaustiveSwitchStatements1.ts, 33, 8)) + + case E.B: return 1 +>E.B : Symbol(E.B, Decl(exhaustiveSwitchStatements1.ts, 33, 11)) +>E : Symbol(E, Decl(exhaustiveSwitchStatements1.ts, 29, 1)) +>B : Symbol(E.B, Decl(exhaustiveSwitchStatements1.ts, 33, 11)) + } +} + +// Repro from #12668 + +interface Square { kind: "square"; size: number; } +>Square : Symbol(Square, Decl(exhaustiveSwitchStatements1.ts, 50, 1)) +>kind : Symbol(Square.kind, Decl(exhaustiveSwitchStatements1.ts, 54, 18)) +>size : Symbol(Square.size, Decl(exhaustiveSwitchStatements1.ts, 54, 34)) + +interface Rectangle { kind: "rectangle"; width: number; height: number; } +>Rectangle : Symbol(Rectangle, Decl(exhaustiveSwitchStatements1.ts, 54, 50)) +>kind : Symbol(Rectangle.kind, Decl(exhaustiveSwitchStatements1.ts, 56, 21)) +>width : Symbol(Rectangle.width, Decl(exhaustiveSwitchStatements1.ts, 56, 40)) +>height : Symbol(Rectangle.height, Decl(exhaustiveSwitchStatements1.ts, 56, 55)) + +interface Circle { kind: "circle"; radius: number; } +>Circle : Symbol(Circle, Decl(exhaustiveSwitchStatements1.ts, 56, 73)) +>kind : Symbol(Circle.kind, Decl(exhaustiveSwitchStatements1.ts, 58, 18)) +>radius : Symbol(Circle.radius, Decl(exhaustiveSwitchStatements1.ts, 58, 34)) + +interface Triangle { kind: "triangle"; side: number; } +>Triangle : Symbol(Triangle, Decl(exhaustiveSwitchStatements1.ts, 58, 52)) +>kind : Symbol(Triangle.kind, Decl(exhaustiveSwitchStatements1.ts, 60, 20)) +>side : Symbol(Triangle.side, Decl(exhaustiveSwitchStatements1.ts, 60, 38)) + +type Shape = Square | Rectangle | Circle | Triangle; +>Shape : Symbol(Shape, Decl(exhaustiveSwitchStatements1.ts, 60, 54)) +>Square : Symbol(Square, Decl(exhaustiveSwitchStatements1.ts, 50, 1)) +>Rectangle : Symbol(Rectangle, Decl(exhaustiveSwitchStatements1.ts, 54, 50)) +>Circle : Symbol(Circle, Decl(exhaustiveSwitchStatements1.ts, 56, 73)) +>Triangle : Symbol(Triangle, Decl(exhaustiveSwitchStatements1.ts, 58, 52)) + +function area(s: Shape): number { +>area : Symbol(area, Decl(exhaustiveSwitchStatements1.ts, 62, 52)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 64, 14)) +>Shape : Symbol(Shape, Decl(exhaustiveSwitchStatements1.ts, 60, 54)) + + let area; +>area : Symbol(area, Decl(exhaustiveSwitchStatements1.ts, 65, 7)) + + switch (s.kind) { +>s.kind : Symbol(kind, Decl(exhaustiveSwitchStatements1.ts, 54, 18), Decl(exhaustiveSwitchStatements1.ts, 56, 21), Decl(exhaustiveSwitchStatements1.ts, 58, 18), Decl(exhaustiveSwitchStatements1.ts, 60, 20)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 64, 14)) +>kind : Symbol(kind, Decl(exhaustiveSwitchStatements1.ts, 54, 18), Decl(exhaustiveSwitchStatements1.ts, 56, 21), Decl(exhaustiveSwitchStatements1.ts, 58, 18), Decl(exhaustiveSwitchStatements1.ts, 60, 20)) + + case "square": area = s.size * s.size; break; +>area : Symbol(area, Decl(exhaustiveSwitchStatements1.ts, 65, 7)) +>s.size : Symbol(Square.size, Decl(exhaustiveSwitchStatements1.ts, 54, 34)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 64, 14)) +>size : Symbol(Square.size, Decl(exhaustiveSwitchStatements1.ts, 54, 34)) +>s.size : Symbol(Square.size, Decl(exhaustiveSwitchStatements1.ts, 54, 34)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 64, 14)) +>size : Symbol(Square.size, Decl(exhaustiveSwitchStatements1.ts, 54, 34)) + + case "rectangle": area = s.width * s.height; break; +>area : Symbol(area, Decl(exhaustiveSwitchStatements1.ts, 65, 7)) +>s.width : Symbol(Rectangle.width, Decl(exhaustiveSwitchStatements1.ts, 56, 40)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 64, 14)) +>width : Symbol(Rectangle.width, Decl(exhaustiveSwitchStatements1.ts, 56, 40)) +>s.height : Symbol(Rectangle.height, Decl(exhaustiveSwitchStatements1.ts, 56, 55)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 64, 14)) +>height : Symbol(Rectangle.height, Decl(exhaustiveSwitchStatements1.ts, 56, 55)) + + case "circle": area = Math.PI * s.radius * s.radius; break; +>area : Symbol(area, Decl(exhaustiveSwitchStatements1.ts, 65, 7)) +>Math.PI : Symbol(Math.PI, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>PI : Symbol(Math.PI, Decl(lib.es5.d.ts, --, --)) +>s.radius : Symbol(Circle.radius, Decl(exhaustiveSwitchStatements1.ts, 58, 34)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 64, 14)) +>radius : Symbol(Circle.radius, Decl(exhaustiveSwitchStatements1.ts, 58, 34)) +>s.radius : Symbol(Circle.radius, Decl(exhaustiveSwitchStatements1.ts, 58, 34)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 64, 14)) +>radius : Symbol(Circle.radius, Decl(exhaustiveSwitchStatements1.ts, 58, 34)) + + case "triangle": area = Math.sqrt(3) / 4 * s.side * s.side; break; +>area : Symbol(area, Decl(exhaustiveSwitchStatements1.ts, 65, 7)) +>Math.sqrt : Symbol(Math.sqrt, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>sqrt : Symbol(Math.sqrt, Decl(lib.es5.d.ts, --, --)) +>s.side : Symbol(Triangle.side, Decl(exhaustiveSwitchStatements1.ts, 60, 38)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 64, 14)) +>side : Symbol(Triangle.side, Decl(exhaustiveSwitchStatements1.ts, 60, 38)) +>s.side : Symbol(Triangle.side, Decl(exhaustiveSwitchStatements1.ts, 60, 38)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 64, 14)) +>side : Symbol(Triangle.side, Decl(exhaustiveSwitchStatements1.ts, 60, 38)) + } + return area; +>area : Symbol(area, Decl(exhaustiveSwitchStatements1.ts, 65, 7)) +} + +function areaWrapped(s: Shape): number { +>areaWrapped : Symbol(areaWrapped, Decl(exhaustiveSwitchStatements1.ts, 73, 1)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 75, 21)) +>Shape : Symbol(Shape, Decl(exhaustiveSwitchStatements1.ts, 60, 54)) + + let area; +>area : Symbol(area, Decl(exhaustiveSwitchStatements1.ts, 76, 7)) + + area = (() => { +>area : Symbol(area, Decl(exhaustiveSwitchStatements1.ts, 76, 7)) + + switch (s.kind) { +>s.kind : Symbol(kind, Decl(exhaustiveSwitchStatements1.ts, 54, 18), Decl(exhaustiveSwitchStatements1.ts, 56, 21), Decl(exhaustiveSwitchStatements1.ts, 58, 18), Decl(exhaustiveSwitchStatements1.ts, 60, 20)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 75, 21)) +>kind : Symbol(kind, Decl(exhaustiveSwitchStatements1.ts, 54, 18), Decl(exhaustiveSwitchStatements1.ts, 56, 21), Decl(exhaustiveSwitchStatements1.ts, 58, 18), Decl(exhaustiveSwitchStatements1.ts, 60, 20)) + + case "square": return s.size * s.size; +>s.size : Symbol(Square.size, Decl(exhaustiveSwitchStatements1.ts, 54, 34)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 75, 21)) +>size : Symbol(Square.size, Decl(exhaustiveSwitchStatements1.ts, 54, 34)) +>s.size : Symbol(Square.size, Decl(exhaustiveSwitchStatements1.ts, 54, 34)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 75, 21)) +>size : Symbol(Square.size, Decl(exhaustiveSwitchStatements1.ts, 54, 34)) + + case "rectangle": return s.width * s.height; +>s.width : Symbol(Rectangle.width, Decl(exhaustiveSwitchStatements1.ts, 56, 40)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 75, 21)) +>width : Symbol(Rectangle.width, Decl(exhaustiveSwitchStatements1.ts, 56, 40)) +>s.height : Symbol(Rectangle.height, Decl(exhaustiveSwitchStatements1.ts, 56, 55)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 75, 21)) +>height : Symbol(Rectangle.height, Decl(exhaustiveSwitchStatements1.ts, 56, 55)) + + case "circle": return Math.PI * s.radius * s.radius; +>Math.PI : Symbol(Math.PI, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>PI : Symbol(Math.PI, Decl(lib.es5.d.ts, --, --)) +>s.radius : Symbol(Circle.radius, Decl(exhaustiveSwitchStatements1.ts, 58, 34)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 75, 21)) +>radius : Symbol(Circle.radius, Decl(exhaustiveSwitchStatements1.ts, 58, 34)) +>s.radius : Symbol(Circle.radius, Decl(exhaustiveSwitchStatements1.ts, 58, 34)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 75, 21)) +>radius : Symbol(Circle.radius, Decl(exhaustiveSwitchStatements1.ts, 58, 34)) + + case "triangle": return Math.sqrt(3) / 4 * s.side * s.side; +>Math.sqrt : Symbol(Math.sqrt, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>sqrt : Symbol(Math.sqrt, Decl(lib.es5.d.ts, --, --)) +>s.side : Symbol(Triangle.side, Decl(exhaustiveSwitchStatements1.ts, 60, 38)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 75, 21)) +>side : Symbol(Triangle.side, Decl(exhaustiveSwitchStatements1.ts, 60, 38)) +>s.side : Symbol(Triangle.side, Decl(exhaustiveSwitchStatements1.ts, 60, 38)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 75, 21)) +>side : Symbol(Triangle.side, Decl(exhaustiveSwitchStatements1.ts, 60, 38)) + } + })(); + return area; +>area : Symbol(area, Decl(exhaustiveSwitchStatements1.ts, 76, 7)) +} + +// Repro from #13241 + +enum MyEnum { +>MyEnum : Symbol(MyEnum, Decl(exhaustiveSwitchStatements1.ts, 86, 1)) + + A, +>A : Symbol(MyEnum.A, Decl(exhaustiveSwitchStatements1.ts, 90, 13)) + + B +>B : Symbol(MyEnum.B, Decl(exhaustiveSwitchStatements1.ts, 91, 3)) +} + +function thisGivesError(e: MyEnum): string { +>thisGivesError : Symbol(thisGivesError, Decl(exhaustiveSwitchStatements1.ts, 93, 1)) +>e : Symbol(e, Decl(exhaustiveSwitchStatements1.ts, 95, 24)) +>MyEnum : Symbol(MyEnum, Decl(exhaustiveSwitchStatements1.ts, 86, 1)) + + let s: string; +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 96, 4)) + + switch (e) { +>e : Symbol(e, Decl(exhaustiveSwitchStatements1.ts, 95, 24)) + + case MyEnum.A: s = "it was A"; break; +>MyEnum.A : Symbol(MyEnum.A, Decl(exhaustiveSwitchStatements1.ts, 90, 13)) +>MyEnum : Symbol(MyEnum, Decl(exhaustiveSwitchStatements1.ts, 86, 1)) +>A : Symbol(MyEnum.A, Decl(exhaustiveSwitchStatements1.ts, 90, 13)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 96, 4)) + + case MyEnum.B: s = "it was B"; break; +>MyEnum.B : Symbol(MyEnum.B, Decl(exhaustiveSwitchStatements1.ts, 91, 3)) +>MyEnum : Symbol(MyEnum, Decl(exhaustiveSwitchStatements1.ts, 86, 1)) +>B : Symbol(MyEnum.B, Decl(exhaustiveSwitchStatements1.ts, 91, 3)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 96, 4)) + } + return s; +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 96, 4)) +} + +function good1(e: MyEnum): string { +>good1 : Symbol(good1, Decl(exhaustiveSwitchStatements1.ts, 102, 1)) +>e : Symbol(e, Decl(exhaustiveSwitchStatements1.ts, 104, 15)) +>MyEnum : Symbol(MyEnum, Decl(exhaustiveSwitchStatements1.ts, 86, 1)) + + let s: string; +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 105, 4)) + + switch (e) { +>e : Symbol(e, Decl(exhaustiveSwitchStatements1.ts, 104, 15)) + + case MyEnum.A: s = "it was A"; break; +>MyEnum.A : Symbol(MyEnum.A, Decl(exhaustiveSwitchStatements1.ts, 90, 13)) +>MyEnum : Symbol(MyEnum, Decl(exhaustiveSwitchStatements1.ts, 86, 1)) +>A : Symbol(MyEnum.A, Decl(exhaustiveSwitchStatements1.ts, 90, 13)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 105, 4)) + + case MyEnum.B: s = "it was B"; break; +>MyEnum.B : Symbol(MyEnum.B, Decl(exhaustiveSwitchStatements1.ts, 91, 3)) +>MyEnum : Symbol(MyEnum, Decl(exhaustiveSwitchStatements1.ts, 86, 1)) +>B : Symbol(MyEnum.B, Decl(exhaustiveSwitchStatements1.ts, 91, 3)) +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 105, 4)) + + default: s = "it was something else"; break; +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 105, 4)) + } + return s; +>s : Symbol(s, Decl(exhaustiveSwitchStatements1.ts, 105, 4)) +} + +function good2(e: MyEnum): string { +>good2 : Symbol(good2, Decl(exhaustiveSwitchStatements1.ts, 112, 1)) +>e : Symbol(e, Decl(exhaustiveSwitchStatements1.ts, 114, 15)) +>MyEnum : Symbol(MyEnum, Decl(exhaustiveSwitchStatements1.ts, 86, 1)) + + switch (e) { +>e : Symbol(e, Decl(exhaustiveSwitchStatements1.ts, 114, 15)) + + case MyEnum.A: return "it was A"; +>MyEnum.A : Symbol(MyEnum.A, Decl(exhaustiveSwitchStatements1.ts, 90, 13)) +>MyEnum : Symbol(MyEnum, Decl(exhaustiveSwitchStatements1.ts, 86, 1)) +>A : Symbol(MyEnum.A, Decl(exhaustiveSwitchStatements1.ts, 90, 13)) + + case MyEnum.B: return "it was B"; +>MyEnum.B : Symbol(MyEnum.B, Decl(exhaustiveSwitchStatements1.ts, 91, 3)) +>MyEnum : Symbol(MyEnum, Decl(exhaustiveSwitchStatements1.ts, 86, 1)) +>B : Symbol(MyEnum.B, Decl(exhaustiveSwitchStatements1.ts, 91, 3)) + } +} + +// Repro from #18362 + +enum Level { +>Level : Symbol(Level, Decl(exhaustiveSwitchStatements1.ts, 119, 1)) + + One, +>One : Symbol(Level.One, Decl(exhaustiveSwitchStatements1.ts, 123, 12)) + + Two, +>Two : Symbol(Level.Two, Decl(exhaustiveSwitchStatements1.ts, 124, 6)) +} + +const doSomethingWithLevel = (level: Level) => { +>doSomethingWithLevel : Symbol(doSomethingWithLevel, Decl(exhaustiveSwitchStatements1.ts, 128, 5)) +>level : Symbol(level, Decl(exhaustiveSwitchStatements1.ts, 128, 30)) +>Level : Symbol(Level, Decl(exhaustiveSwitchStatements1.ts, 119, 1)) + + let next: Level; +>next : Symbol(next, Decl(exhaustiveSwitchStatements1.ts, 129, 5)) +>Level : Symbol(Level, Decl(exhaustiveSwitchStatements1.ts, 119, 1)) + + switch (level) { +>level : Symbol(level, Decl(exhaustiveSwitchStatements1.ts, 128, 30)) + + case Level.One: +>Level.One : Symbol(Level.One, Decl(exhaustiveSwitchStatements1.ts, 123, 12)) +>Level : Symbol(Level, Decl(exhaustiveSwitchStatements1.ts, 119, 1)) +>One : Symbol(Level.One, Decl(exhaustiveSwitchStatements1.ts, 123, 12)) + + next = Level.Two; +>next : Symbol(next, Decl(exhaustiveSwitchStatements1.ts, 129, 5)) +>Level.Two : Symbol(Level.Two, Decl(exhaustiveSwitchStatements1.ts, 124, 6)) +>Level : Symbol(Level, Decl(exhaustiveSwitchStatements1.ts, 119, 1)) +>Two : Symbol(Level.Two, Decl(exhaustiveSwitchStatements1.ts, 124, 6)) + + break; + case Level.Two: +>Level.Two : Symbol(Level.Two, Decl(exhaustiveSwitchStatements1.ts, 124, 6)) +>Level : Symbol(Level, Decl(exhaustiveSwitchStatements1.ts, 119, 1)) +>Two : Symbol(Level.Two, Decl(exhaustiveSwitchStatements1.ts, 124, 6)) + + next = Level.One; +>next : Symbol(next, Decl(exhaustiveSwitchStatements1.ts, 129, 5)) +>Level.One : Symbol(Level.One, Decl(exhaustiveSwitchStatements1.ts, 123, 12)) +>Level : Symbol(Level, Decl(exhaustiveSwitchStatements1.ts, 119, 1)) +>One : Symbol(Level.One, Decl(exhaustiveSwitchStatements1.ts, 123, 12)) + + break; + } + return next; +>next : Symbol(next, Decl(exhaustiveSwitchStatements1.ts, 129, 5)) + +}; + +// Repro from #20409 + +interface Square2 { +>Square2 : Symbol(Square2, Decl(exhaustiveSwitchStatements1.ts, 139, 2)) + + kind: "square"; +>kind : Symbol(Square2.kind, Decl(exhaustiveSwitchStatements1.ts, 143, 19)) + + size: number; +>size : Symbol(Square2.size, Decl(exhaustiveSwitchStatements1.ts, 144, 19)) +} + +interface Circle2 { +>Circle2 : Symbol(Circle2, Decl(exhaustiveSwitchStatements1.ts, 146, 1)) + + kind: "circle"; +>kind : Symbol(Circle2.kind, Decl(exhaustiveSwitchStatements1.ts, 148, 19)) + + radius: number; +>radius : Symbol(Circle2.radius, Decl(exhaustiveSwitchStatements1.ts, 149, 19)) +} + +type Shape2 = Square2 | Circle2; +>Shape2 : Symbol(Shape2, Decl(exhaustiveSwitchStatements1.ts, 151, 1)) +>Square2 : Symbol(Square2, Decl(exhaustiveSwitchStatements1.ts, 139, 2)) +>Circle2 : Symbol(Circle2, Decl(exhaustiveSwitchStatements1.ts, 146, 1)) + +function withDefault(s1: Shape2, s2: Shape2): string { +>withDefault : Symbol(withDefault, Decl(exhaustiveSwitchStatements1.ts, 153, 32)) +>s1 : Symbol(s1, Decl(exhaustiveSwitchStatements1.ts, 155, 21)) +>Shape2 : Symbol(Shape2, Decl(exhaustiveSwitchStatements1.ts, 151, 1)) +>s2 : Symbol(s2, Decl(exhaustiveSwitchStatements1.ts, 155, 32)) +>Shape2 : Symbol(Shape2, Decl(exhaustiveSwitchStatements1.ts, 151, 1)) + + switch (s1.kind) { +>s1.kind : Symbol(kind, Decl(exhaustiveSwitchStatements1.ts, 143, 19), Decl(exhaustiveSwitchStatements1.ts, 148, 19)) +>s1 : Symbol(s1, Decl(exhaustiveSwitchStatements1.ts, 155, 21)) +>kind : Symbol(kind, Decl(exhaustiveSwitchStatements1.ts, 143, 19), Decl(exhaustiveSwitchStatements1.ts, 148, 19)) + + case "square": + return "1"; + case "circle": + switch (s2.kind) { +>s2.kind : Symbol(kind, Decl(exhaustiveSwitchStatements1.ts, 143, 19), Decl(exhaustiveSwitchStatements1.ts, 148, 19)) +>s2 : Symbol(s2, Decl(exhaustiveSwitchStatements1.ts, 155, 32)) +>kind : Symbol(kind, Decl(exhaustiveSwitchStatements1.ts, 143, 19), Decl(exhaustiveSwitchStatements1.ts, 148, 19)) + + case "square": + return "2"; + case "circle": + return "3"; + default: + return "never"; + } + } +} + +function withoutDefault(s1: Shape2, s2: Shape2): string { +>withoutDefault : Symbol(withoutDefault, Decl(exhaustiveSwitchStatements1.ts, 169, 1)) +>s1 : Symbol(s1, Decl(exhaustiveSwitchStatements1.ts, 171, 24)) +>Shape2 : Symbol(Shape2, Decl(exhaustiveSwitchStatements1.ts, 151, 1)) +>s2 : Symbol(s2, Decl(exhaustiveSwitchStatements1.ts, 171, 35)) +>Shape2 : Symbol(Shape2, Decl(exhaustiveSwitchStatements1.ts, 151, 1)) + + switch (s1.kind) { +>s1.kind : Symbol(kind, Decl(exhaustiveSwitchStatements1.ts, 143, 19), Decl(exhaustiveSwitchStatements1.ts, 148, 19)) +>s1 : Symbol(s1, Decl(exhaustiveSwitchStatements1.ts, 171, 24)) +>kind : Symbol(kind, Decl(exhaustiveSwitchStatements1.ts, 143, 19), Decl(exhaustiveSwitchStatements1.ts, 148, 19)) + + case "square": + return "1"; + case "circle": + switch (s2.kind) { +>s2.kind : Symbol(kind, Decl(exhaustiveSwitchStatements1.ts, 143, 19), Decl(exhaustiveSwitchStatements1.ts, 148, 19)) +>s2 : Symbol(s2, Decl(exhaustiveSwitchStatements1.ts, 171, 35)) +>kind : Symbol(kind, Decl(exhaustiveSwitchStatements1.ts, 143, 19), Decl(exhaustiveSwitchStatements1.ts, 148, 19)) + + case "square": + return "2"; + case "circle": + return "3"; + } + } +} + +// Repro from #20823 + +function test4(value: 1 | 2) { +>test4 : Symbol(test4, Decl(exhaustiveSwitchStatements1.ts, 183, 1)) +>value : Symbol(value, Decl(exhaustiveSwitchStatements1.ts, 187, 15)) + + let x: string; +>x : Symbol(x, Decl(exhaustiveSwitchStatements1.ts, 188, 7)) + + switch (value) { +>value : Symbol(value, Decl(exhaustiveSwitchStatements1.ts, 187, 15)) + + case 1: x = "one"; break; +>x : Symbol(x, Decl(exhaustiveSwitchStatements1.ts, 188, 7)) + + case 2: x = "two"; break; +>x : Symbol(x, Decl(exhaustiveSwitchStatements1.ts, 188, 7)) + } + return x; +>x : Symbol(x, Decl(exhaustiveSwitchStatements1.ts, 188, 7)) +} + diff --git a/tests/baselines/reference/exhaustiveSwitchStatements1.types b/tests/baselines/reference/exhaustiveSwitchStatements1.types new file mode 100644 index 00000000000..04a9bf531ce --- /dev/null +++ b/tests/baselines/reference/exhaustiveSwitchStatements1.types @@ -0,0 +1,595 @@ +=== tests/cases/conformance/controlFlow/exhaustiveSwitchStatements1.ts === +function f1(x: 1 | 2): string { +>f1 : (x: 1 | 2) => string +>x : 1 | 2 + + if (!!true) { +>!!true : true +>!true : false +>true : true + + switch (x) { +>x : 1 | 2 + + case 1: return 'a'; +>1 : 1 +>'a' : "a" + + case 2: return 'b'; +>2 : 2 +>'b' : "b" + } + x; // Unreachable +>x : never + } + else { + throw 0; +>0 : 0 + } +} + +function f2(x: 1 | 2) { +>f2 : (x: 1 | 2) => void +>x : 1 | 2 + + let z: number; +>z : number + + switch (x) { +>x : 1 | 2 + + case 1: z = 10; break; +>1 : 1 +>z = 10 : 10 +>z : number +>10 : 10 + + case 2: z = 20; break; +>2 : 2 +>z = 20 : 20 +>z : number +>20 : 20 + } + z; // Definitely assigned +>z : number +} + +function f3(x: 1 | 2) { +>f3 : (x: 1 | 2) => 10 | 20 +>x : 1 | 2 + + switch (x) { +>x : 1 | 2 + + case 1: return 10; +>1 : 1 +>10 : 10 + + case 2: return 20; +>2 : 2 +>20 : 20 + + // Default considered reachable to allow defensive coding + default: throw new Error("Bad input"); +>new Error("Bad input") : Error +>Error : ErrorConstructor +>"Bad input" : "Bad input" + } +} + +// Repro from #11572 + +enum E { A, B } +>E : E +>A : E.A +>B : E.B + +function f(e: E): number { +>f : (e: E) => number +>e : E + + switch (e) { +>e : E + + case E.A: return 0 +>E.A : E.A +>E : typeof E +>A : E.A +>0 : 0 + + case E.B: return 1 +>E.B : E.B +>E : typeof E +>B : E.B +>1 : 1 + } +} + +function g(e: E): number { +>g : (e: E) => number +>e : E + + if (!true) +>!true : false +>true : true + + return -1 +>-1 : -1 +>1 : 1 + + else + switch (e) { +>e : E + + case E.A: return 0 +>E.A : E.A +>E : typeof E +>A : E.A +>0 : 0 + + case E.B: return 1 +>E.B : E.B +>E : typeof E +>B : E.B +>1 : 1 + } +} + +// Repro from #12668 + +interface Square { kind: "square"; size: number; } +>kind : "square" +>size : number + +interface Rectangle { kind: "rectangle"; width: number; height: number; } +>kind : "rectangle" +>width : number +>height : number + +interface Circle { kind: "circle"; radius: number; } +>kind : "circle" +>radius : number + +interface Triangle { kind: "triangle"; side: number; } +>kind : "triangle" +>side : number + +type Shape = Square | Rectangle | Circle | Triangle; +>Shape : Shape + +function area(s: Shape): number { +>area : (s: Shape) => number +>s : Shape + + let area; +>area : any + + switch (s.kind) { +>s.kind : "square" | "rectangle" | "circle" | "triangle" +>s : Shape +>kind : "square" | "rectangle" | "circle" | "triangle" + + case "square": area = s.size * s.size; break; +>"square" : "square" +>area = s.size * s.size : number +>area : any +>s.size * s.size : number +>s.size : number +>s : Square +>size : number +>s.size : number +>s : Square +>size : number + + case "rectangle": area = s.width * s.height; break; +>"rectangle" : "rectangle" +>area = s.width * s.height : number +>area : any +>s.width * s.height : number +>s.width : number +>s : Rectangle +>width : number +>s.height : number +>s : Rectangle +>height : number + + case "circle": area = Math.PI * s.radius * s.radius; break; +>"circle" : "circle" +>area = Math.PI * s.radius * s.radius : number +>area : any +>Math.PI * s.radius * s.radius : number +>Math.PI * s.radius : number +>Math.PI : number +>Math : Math +>PI : number +>s.radius : number +>s : Circle +>radius : number +>s.radius : number +>s : Circle +>radius : number + + case "triangle": area = Math.sqrt(3) / 4 * s.side * s.side; break; +>"triangle" : "triangle" +>area = Math.sqrt(3) / 4 * s.side * s.side : number +>area : any +>Math.sqrt(3) / 4 * s.side * s.side : number +>Math.sqrt(3) / 4 * s.side : number +>Math.sqrt(3) / 4 : number +>Math.sqrt(3) : number +>Math.sqrt : (x: number) => number +>Math : Math +>sqrt : (x: number) => number +>3 : 3 +>4 : 4 +>s.side : number +>s : Triangle +>side : number +>s.side : number +>s : Triangle +>side : number + } + return area; +>area : number +} + +function areaWrapped(s: Shape): number { +>areaWrapped : (s: Shape) => number +>s : Shape + + let area; +>area : any + + area = (() => { +>area = (() => { switch (s.kind) { case "square": return s.size * s.size; case "rectangle": return s.width * s.height; case "circle": return Math.PI * s.radius * s.radius; case "triangle": return Math.sqrt(3) / 4 * s.side * s.side; } })() : number +>area : any +>(() => { switch (s.kind) { case "square": return s.size * s.size; case "rectangle": return s.width * s.height; case "circle": return Math.PI * s.radius * s.radius; case "triangle": return Math.sqrt(3) / 4 * s.side * s.side; } })() : number +>(() => { switch (s.kind) { case "square": return s.size * s.size; case "rectangle": return s.width * s.height; case "circle": return Math.PI * s.radius * s.radius; case "triangle": return Math.sqrt(3) / 4 * s.side * s.side; } }) : () => number +>() => { switch (s.kind) { case "square": return s.size * s.size; case "rectangle": return s.width * s.height; case "circle": return Math.PI * s.radius * s.radius; case "triangle": return Math.sqrt(3) / 4 * s.side * s.side; } } : () => number + + switch (s.kind) { +>s.kind : "square" | "rectangle" | "circle" | "triangle" +>s : Shape +>kind : "square" | "rectangle" | "circle" | "triangle" + + case "square": return s.size * s.size; +>"square" : "square" +>s.size * s.size : number +>s.size : number +>s : Square +>size : number +>s.size : number +>s : Square +>size : number + + case "rectangle": return s.width * s.height; +>"rectangle" : "rectangle" +>s.width * s.height : number +>s.width : number +>s : Rectangle +>width : number +>s.height : number +>s : Rectangle +>height : number + + case "circle": return Math.PI * s.radius * s.radius; +>"circle" : "circle" +>Math.PI * s.radius * s.radius : number +>Math.PI * s.radius : number +>Math.PI : number +>Math : Math +>PI : number +>s.radius : number +>s : Circle +>radius : number +>s.radius : number +>s : Circle +>radius : number + + case "triangle": return Math.sqrt(3) / 4 * s.side * s.side; +>"triangle" : "triangle" +>Math.sqrt(3) / 4 * s.side * s.side : number +>Math.sqrt(3) / 4 * s.side : number +>Math.sqrt(3) / 4 : number +>Math.sqrt(3) : number +>Math.sqrt : (x: number) => number +>Math : Math +>sqrt : (x: number) => number +>3 : 3 +>4 : 4 +>s.side : number +>s : Triangle +>side : number +>s.side : number +>s : Triangle +>side : number + } + })(); + return area; +>area : number +} + +// Repro from #13241 + +enum MyEnum { +>MyEnum : MyEnum + + A, +>A : MyEnum.A + + B +>B : MyEnum.B +} + +function thisGivesError(e: MyEnum): string { +>thisGivesError : (e: MyEnum) => string +>e : MyEnum + + let s: string; +>s : string + + switch (e) { +>e : MyEnum + + case MyEnum.A: s = "it was A"; break; +>MyEnum.A : MyEnum.A +>MyEnum : typeof MyEnum +>A : MyEnum.A +>s = "it was A" : "it was A" +>s : string +>"it was A" : "it was A" + + case MyEnum.B: s = "it was B"; break; +>MyEnum.B : MyEnum.B +>MyEnum : typeof MyEnum +>B : MyEnum.B +>s = "it was B" : "it was B" +>s : string +>"it was B" : "it was B" + } + return s; +>s : string +} + +function good1(e: MyEnum): string { +>good1 : (e: MyEnum) => string +>e : MyEnum + + let s: string; +>s : string + + switch (e) { +>e : MyEnum + + case MyEnum.A: s = "it was A"; break; +>MyEnum.A : MyEnum.A +>MyEnum : typeof MyEnum +>A : MyEnum.A +>s = "it was A" : "it was A" +>s : string +>"it was A" : "it was A" + + case MyEnum.B: s = "it was B"; break; +>MyEnum.B : MyEnum.B +>MyEnum : typeof MyEnum +>B : MyEnum.B +>s = "it was B" : "it was B" +>s : string +>"it was B" : "it was B" + + default: s = "it was something else"; break; +>s = "it was something else" : "it was something else" +>s : string +>"it was something else" : "it was something else" + } + return s; +>s : string +} + +function good2(e: MyEnum): string { +>good2 : (e: MyEnum) => string +>e : MyEnum + + switch (e) { +>e : MyEnum + + case MyEnum.A: return "it was A"; +>MyEnum.A : MyEnum.A +>MyEnum : typeof MyEnum +>A : MyEnum.A +>"it was A" : "it was A" + + case MyEnum.B: return "it was B"; +>MyEnum.B : MyEnum.B +>MyEnum : typeof MyEnum +>B : MyEnum.B +>"it was B" : "it was B" + } +} + +// Repro from #18362 + +enum Level { +>Level : Level + + One, +>One : Level.One + + Two, +>Two : Level.Two +} + +const doSomethingWithLevel = (level: Level) => { +>doSomethingWithLevel : (level: Level) => Level +>(level: Level) => { let next: Level; switch (level) { case Level.One: next = Level.Two; break; case Level.Two: next = Level.One; break; } return next;} : (level: Level) => Level +>level : Level + + let next: Level; +>next : Level + + switch (level) { +>level : Level + + case Level.One: +>Level.One : Level.One +>Level : typeof Level +>One : Level.One + + next = Level.Two; +>next = Level.Two : Level.Two +>next : Level +>Level.Two : Level.Two +>Level : typeof Level +>Two : Level.Two + + break; + case Level.Two: +>Level.Two : Level.Two +>Level : typeof Level +>Two : Level.Two + + next = Level.One; +>next = Level.One : Level.One +>next : Level +>Level.One : Level.One +>Level : typeof Level +>One : Level.One + + break; + } + return next; +>next : Level + +}; + +// Repro from #20409 + +interface Square2 { + kind: "square"; +>kind : "square" + + size: number; +>size : number +} + +interface Circle2 { + kind: "circle"; +>kind : "circle" + + radius: number; +>radius : number +} + +type Shape2 = Square2 | Circle2; +>Shape2 : Shape2 + +function withDefault(s1: Shape2, s2: Shape2): string { +>withDefault : (s1: Shape2, s2: Shape2) => string +>s1 : Shape2 +>s2 : Shape2 + + switch (s1.kind) { +>s1.kind : "square" | "circle" +>s1 : Shape2 +>kind : "square" | "circle" + + case "square": +>"square" : "square" + + return "1"; +>"1" : "1" + + case "circle": +>"circle" : "circle" + + switch (s2.kind) { +>s2.kind : "square" | "circle" +>s2 : Shape2 +>kind : "square" | "circle" + + case "square": +>"square" : "square" + + return "2"; +>"2" : "2" + + case "circle": +>"circle" : "circle" + + return "3"; +>"3" : "3" + + default: + return "never"; +>"never" : "never" + } + } +} + +function withoutDefault(s1: Shape2, s2: Shape2): string { +>withoutDefault : (s1: Shape2, s2: Shape2) => string +>s1 : Shape2 +>s2 : Shape2 + + switch (s1.kind) { +>s1.kind : "square" | "circle" +>s1 : Shape2 +>kind : "square" | "circle" + + case "square": +>"square" : "square" + + return "1"; +>"1" : "1" + + case "circle": +>"circle" : "circle" + + switch (s2.kind) { +>s2.kind : "square" | "circle" +>s2 : Shape2 +>kind : "square" | "circle" + + case "square": +>"square" : "square" + + return "2"; +>"2" : "2" + + case "circle": +>"circle" : "circle" + + return "3"; +>"3" : "3" + } + } +} + +// Repro from #20823 + +function test4(value: 1 | 2) { +>test4 : (value: 1 | 2) => string +>value : 1 | 2 + + let x: string; +>x : string + + switch (value) { +>value : 1 | 2 + + case 1: x = "one"; break; +>1 : 1 +>x = "one" : "one" +>x : string +>"one" : "one" + + case 2: x = "two"; break; +>2 : 2 +>x = "two" : "two" +>x : string +>"two" : "two" + } + return x; +>x : string +} + diff --git a/tests/baselines/reference/neverReturningFunctions1.errors.txt b/tests/baselines/reference/neverReturningFunctions1.errors.txt new file mode 100644 index 00000000000..f8656bbed08 --- /dev/null +++ b/tests/baselines/reference/neverReturningFunctions1.errors.txt @@ -0,0 +1,227 @@ +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(13,5): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(19,5): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(30,5): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(36,5): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(51,5): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(57,5): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(63,5): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(77,9): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(82,9): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(89,9): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(96,13): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(101,13): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(103,9): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(105,5): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(111,9): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(112,9): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(122,9): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(127,9): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(129,5): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(139,9): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(141,5): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(148,9): error TS7027: Unreachable code detected. +tests/cases/conformance/controlFlow/neverReturningFunctions1.ts(153,5): error TS7027: Unreachable code detected. + + +==== tests/cases/conformance/controlFlow/neverReturningFunctions1.ts (23 errors) ==== + function fail(message?: string): never { + throw new Error(message); + } + + function f01(x: string | undefined) { + if (x === undefined) fail("undefined argument"); + x.length; // string + } + + function f02(x: number): number { + if (x >= 0) return x; + fail("negative number"); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + + function f03(x: string) { + x; // string + fail(); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + + function f11(x: string | undefined, fail: (message?: string) => never) { + if (x === undefined) fail("undefined argument"); + x.length; // string + } + + function f12(x: number, fail: (message?: string) => never): number { + if (x >= 0) return x; + fail("negative number"); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + + function f13(x: string, fail: (message?: string) => never) { + x; // string + fail(); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + + namespace Debug { + export declare function fail(message?: string): never; + } + + function f21(x: string | undefined) { + if (x === undefined) Debug.fail("undefined argument"); + x.length; // string + } + + function f22(x: number): number { + if (x >= 0) return x; + Debug.fail("negative number"); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + + function f23(x: string) { + x; // string + Debug.fail(); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + + function f24(x: string) { + x; // string + ((Debug).fail)(); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + + class Test { + fail(message?: string): never { + throw new Error(message); + } + f1(x: string | undefined) { + if (x === undefined) this.fail("undefined argument"); + x.length; // string + } + f2(x: number): number { + if (x >= 0) return x; + this.fail("negative number"); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + f3(x: string) { + x; // string + this.fail(); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + } + + function f30(x: string | number | undefined) { + if (typeof x === "string") { + fail(); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + else { + x; // number | undefined + if (x !== undefined) { + x; // number + fail(); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + else { + x; // undefined + fail(); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + + function f31(x: { a: string | number }) { + if (typeof x.a === "string") { + fail(); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + x.a; // Unreachable + ~~~~ +!!! error TS7027: Unreachable code detected. + } + x; // { a: string | number } + x.a; // number + } + + function f40(x: number) { + try { + x; + fail(); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + finally { + x; + fail(); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + + function f41(x: number) { + try { + x; + } + finally { + x; + fail(); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + + function f42(x: number) { + try { + x; + fail(); + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + finally { + x; + } + x; // Unreachable + ~~ +!!! error TS7027: Unreachable code detected. + } + \ No newline at end of file diff --git a/tests/baselines/reference/neverReturningFunctions1.js b/tests/baselines/reference/neverReturningFunctions1.js new file mode 100644 index 00000000000..cce75c6668a --- /dev/null +++ b/tests/baselines/reference/neverReturningFunctions1.js @@ -0,0 +1,337 @@ +//// [neverReturningFunctions1.ts] +function fail(message?: string): never { + throw new Error(message); +} + +function f01(x: string | undefined) { + if (x === undefined) fail("undefined argument"); + x.length; // string +} + +function f02(x: number): number { + if (x >= 0) return x; + fail("negative number"); + x; // Unreachable +} + +function f03(x: string) { + x; // string + fail(); + x; // Unreachable +} + +function f11(x: string | undefined, fail: (message?: string) => never) { + if (x === undefined) fail("undefined argument"); + x.length; // string +} + +function f12(x: number, fail: (message?: string) => never): number { + if (x >= 0) return x; + fail("negative number"); + x; // Unreachable +} + +function f13(x: string, fail: (message?: string) => never) { + x; // string + fail(); + x; // Unreachable +} + +namespace Debug { + export declare function fail(message?: string): never; +} + +function f21(x: string | undefined) { + if (x === undefined) Debug.fail("undefined argument"); + x.length; // string +} + +function f22(x: number): number { + if (x >= 0) return x; + Debug.fail("negative number"); + x; // Unreachable +} + +function f23(x: string) { + x; // string + Debug.fail(); + x; // Unreachable +} + +function f24(x: string) { + x; // string + ((Debug).fail)(); + x; // Unreachable +} + +class Test { + fail(message?: string): never { + throw new Error(message); + } + f1(x: string | undefined) { + if (x === undefined) this.fail("undefined argument"); + x.length; // string + } + f2(x: number): number { + if (x >= 0) return x; + this.fail("negative number"); + x; // Unreachable + } + f3(x: string) { + x; // string + this.fail(); + x; // Unreachable + } +} + +function f30(x: string | number | undefined) { + if (typeof x === "string") { + fail(); + x; // Unreachable + } + else { + x; // number | undefined + if (x !== undefined) { + x; // number + fail(); + x; // Unreachable + } + else { + x; // undefined + fail(); + x; // Unreachable + } + x; // Unreachable + } + x; // Unreachable +} + +function f31(x: { a: string | number }) { + if (typeof x.a === "string") { + fail(); + x; // Unreachable + x.a; // Unreachable + } + x; // { a: string | number } + x.a; // number +} + +function f40(x: number) { + try { + x; + fail(); + x; // Unreachable + } + finally { + x; + fail(); + x; // Unreachable + } + x; // Unreachable +} + +function f41(x: number) { + try { + x; + } + finally { + x; + fail(); + x; // Unreachable + } + x; // Unreachable +} + +function f42(x: number) { + try { + x; + fail(); + x; // Unreachable + } + finally { + x; + } + x; // Unreachable +} + + +//// [neverReturningFunctions1.js] +"use strict"; +function fail(message) { + throw new Error(message); +} +function f01(x) { + if (x === undefined) + fail("undefined argument"); + x.length; // string +} +function f02(x) { + if (x >= 0) + return x; + fail("negative number"); + x; // Unreachable +} +function f03(x) { + x; // string + fail(); + x; // Unreachable +} +function f11(x, fail) { + if (x === undefined) + fail("undefined argument"); + x.length; // string +} +function f12(x, fail) { + if (x >= 0) + return x; + fail("negative number"); + x; // Unreachable +} +function f13(x, fail) { + x; // string + fail(); + x; // Unreachable +} +var Debug; +(function (Debug) { +})(Debug || (Debug = {})); +function f21(x) { + if (x === undefined) + Debug.fail("undefined argument"); + x.length; // string +} +function f22(x) { + if (x >= 0) + return x; + Debug.fail("negative number"); + x; // Unreachable +} +function f23(x) { + x; // string + Debug.fail(); + x; // Unreachable +} +function f24(x) { + x; // string + ((Debug).fail)(); + x; // Unreachable +} +var Test = /** @class */ (function () { + function Test() { + } + Test.prototype.fail = function (message) { + throw new Error(message); + }; + Test.prototype.f1 = function (x) { + if (x === undefined) + this.fail("undefined argument"); + x.length; // string + }; + Test.prototype.f2 = function (x) { + if (x >= 0) + return x; + this.fail("negative number"); + x; // Unreachable + }; + Test.prototype.f3 = function (x) { + x; // string + this.fail(); + x; // Unreachable + }; + return Test; +}()); +function f30(x) { + if (typeof x === "string") { + fail(); + x; // Unreachable + } + else { + x; // number | undefined + if (x !== undefined) { + x; // number + fail(); + x; // Unreachable + } + else { + x; // undefined + fail(); + x; // Unreachable + } + x; // Unreachable + } + x; // Unreachable +} +function f31(x) { + if (typeof x.a === "string") { + fail(); + x; // Unreachable + x.a; // Unreachable + } + x; // { a: string | number } + x.a; // number +} +function f40(x) { + try { + x; + fail(); + x; // Unreachable + } + finally { + x; + fail(); + x; // Unreachable + } + x; // Unreachable +} +function f41(x) { + try { + x; + } + finally { + x; + fail(); + x; // Unreachable + } + x; // Unreachable +} +function f42(x) { + try { + x; + fail(); + x; // Unreachable + } + finally { + x; + } + x; // Unreachable +} + + +//// [neverReturningFunctions1.d.ts] +declare function fail(message?: string): never; +declare function f01(x: string | undefined): void; +declare function f02(x: number): number; +declare function f03(x: string): void; +declare function f11(x: string | undefined, fail: (message?: string) => never): void; +declare function f12(x: number, fail: (message?: string) => never): number; +declare function f13(x: string, fail: (message?: string) => never): void; +declare namespace Debug { + function fail(message?: string): never; +} +declare function f21(x: string | undefined): void; +declare function f22(x: number): number; +declare function f23(x: string): void; +declare function f24(x: string): void; +declare class Test { + fail(message?: string): never; + f1(x: string | undefined): void; + f2(x: number): number; + f3(x: string): void; +} +declare function f30(x: string | number | undefined): void; +declare function f31(x: { + a: string | number; +}): void; +declare function f40(x: number): void; +declare function f41(x: number): void; +declare function f42(x: number): void; diff --git a/tests/baselines/reference/neverReturningFunctions1.symbols b/tests/baselines/reference/neverReturningFunctions1.symbols new file mode 100644 index 00000000000..7f1b5c489ac --- /dev/null +++ b/tests/baselines/reference/neverReturningFunctions1.symbols @@ -0,0 +1,387 @@ +=== tests/cases/conformance/controlFlow/neverReturningFunctions1.ts === +function fail(message?: string): never { +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 0, 0)) +>message : Symbol(message, Decl(neverReturningFunctions1.ts, 0, 14)) + + throw new Error(message); +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>message : Symbol(message, Decl(neverReturningFunctions1.ts, 0, 14)) +} + +function f01(x: string | undefined) { +>f01 : Symbol(f01, Decl(neverReturningFunctions1.ts, 2, 1)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 4, 13)) + + if (x === undefined) fail("undefined argument"); +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 4, 13)) +>undefined : Symbol(undefined) +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 0, 0)) + + x.length; // string +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 4, 13)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +} + +function f02(x: number): number { +>f02 : Symbol(f02, Decl(neverReturningFunctions1.ts, 7, 1)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 9, 13)) + + if (x >= 0) return x; +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 9, 13)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 9, 13)) + + fail("negative number"); +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 0, 0)) + + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 9, 13)) +} + +function f03(x: string) { +>f03 : Symbol(f03, Decl(neverReturningFunctions1.ts, 13, 1)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 15, 13)) + + x; // string +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 15, 13)) + + fail(); +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 0, 0)) + + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 15, 13)) +} + +function f11(x: string | undefined, fail: (message?: string) => never) { +>f11 : Symbol(f11, Decl(neverReturningFunctions1.ts, 19, 1)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 21, 13)) +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 21, 35)) +>message : Symbol(message, Decl(neverReturningFunctions1.ts, 21, 43)) + + if (x === undefined) fail("undefined argument"); +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 21, 13)) +>undefined : Symbol(undefined) +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 21, 35)) + + x.length; // string +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 21, 13)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +} + +function f12(x: number, fail: (message?: string) => never): number { +>f12 : Symbol(f12, Decl(neverReturningFunctions1.ts, 24, 1)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 26, 13)) +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 26, 23)) +>message : Symbol(message, Decl(neverReturningFunctions1.ts, 26, 31)) + + if (x >= 0) return x; +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 26, 13)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 26, 13)) + + fail("negative number"); +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 26, 23)) + + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 26, 13)) +} + +function f13(x: string, fail: (message?: string) => never) { +>f13 : Symbol(f13, Decl(neverReturningFunctions1.ts, 30, 1)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 32, 13)) +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 32, 23)) +>message : Symbol(message, Decl(neverReturningFunctions1.ts, 32, 31)) + + x; // string +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 32, 13)) + + fail(); +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 32, 23)) + + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 32, 13)) +} + +namespace Debug { +>Debug : Symbol(Debug, Decl(neverReturningFunctions1.ts, 36, 1)) + + export declare function fail(message?: string): never; +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 38, 17)) +>message : Symbol(message, Decl(neverReturningFunctions1.ts, 39, 33)) +} + +function f21(x: string | undefined) { +>f21 : Symbol(f21, Decl(neverReturningFunctions1.ts, 40, 1)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 42, 13)) + + if (x === undefined) Debug.fail("undefined argument"); +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 42, 13)) +>undefined : Symbol(undefined) +>Debug.fail : Symbol(Debug.fail, Decl(neverReturningFunctions1.ts, 38, 17)) +>Debug : Symbol(Debug, Decl(neverReturningFunctions1.ts, 36, 1)) +>fail : Symbol(Debug.fail, Decl(neverReturningFunctions1.ts, 38, 17)) + + x.length; // string +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 42, 13)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +} + +function f22(x: number): number { +>f22 : Symbol(f22, Decl(neverReturningFunctions1.ts, 45, 1)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 47, 13)) + + if (x >= 0) return x; +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 47, 13)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 47, 13)) + + Debug.fail("negative number"); +>Debug.fail : Symbol(Debug.fail, Decl(neverReturningFunctions1.ts, 38, 17)) +>Debug : Symbol(Debug, Decl(neverReturningFunctions1.ts, 36, 1)) +>fail : Symbol(Debug.fail, Decl(neverReturningFunctions1.ts, 38, 17)) + + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 47, 13)) +} + +function f23(x: string) { +>f23 : Symbol(f23, Decl(neverReturningFunctions1.ts, 51, 1)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 53, 13)) + + x; // string +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 53, 13)) + + Debug.fail(); +>Debug.fail : Symbol(Debug.fail, Decl(neverReturningFunctions1.ts, 38, 17)) +>Debug : Symbol(Debug, Decl(neverReturningFunctions1.ts, 36, 1)) +>fail : Symbol(Debug.fail, Decl(neverReturningFunctions1.ts, 38, 17)) + + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 53, 13)) +} + +function f24(x: string) { +>f24 : Symbol(f24, Decl(neverReturningFunctions1.ts, 57, 1)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 59, 13)) + + x; // string +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 59, 13)) + + ((Debug).fail)(); +>(Debug).fail : Symbol(Debug.fail, Decl(neverReturningFunctions1.ts, 38, 17)) +>Debug : Symbol(Debug, Decl(neverReturningFunctions1.ts, 36, 1)) +>fail : Symbol(Debug.fail, Decl(neverReturningFunctions1.ts, 38, 17)) + + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 59, 13)) +} + +class Test { +>Test : Symbol(Test, Decl(neverReturningFunctions1.ts, 63, 1)) + + fail(message?: string): never { +>fail : Symbol(Test.fail, Decl(neverReturningFunctions1.ts, 65, 12)) +>message : Symbol(message, Decl(neverReturningFunctions1.ts, 66, 9)) + + throw new Error(message); +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>message : Symbol(message, Decl(neverReturningFunctions1.ts, 66, 9)) + } + f1(x: string | undefined) { +>f1 : Symbol(Test.f1, Decl(neverReturningFunctions1.ts, 68, 5)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 69, 7)) + + if (x === undefined) this.fail("undefined argument"); +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 69, 7)) +>undefined : Symbol(undefined) +>this.fail : Symbol(Test.fail, Decl(neverReturningFunctions1.ts, 65, 12)) +>this : Symbol(Test, Decl(neverReturningFunctions1.ts, 63, 1)) +>fail : Symbol(Test.fail, Decl(neverReturningFunctions1.ts, 65, 12)) + + x.length; // string +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 69, 7)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + } + f2(x: number): number { +>f2 : Symbol(Test.f2, Decl(neverReturningFunctions1.ts, 72, 5)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 73, 7)) + + if (x >= 0) return x; +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 73, 7)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 73, 7)) + + this.fail("negative number"); +>this.fail : Symbol(Test.fail, Decl(neverReturningFunctions1.ts, 65, 12)) +>this : Symbol(Test, Decl(neverReturningFunctions1.ts, 63, 1)) +>fail : Symbol(Test.fail, Decl(neverReturningFunctions1.ts, 65, 12)) + + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 73, 7)) + } + f3(x: string) { +>f3 : Symbol(Test.f3, Decl(neverReturningFunctions1.ts, 77, 5)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 78, 7)) + + x; // string +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 78, 7)) + + this.fail(); +>this.fail : Symbol(Test.fail, Decl(neverReturningFunctions1.ts, 65, 12)) +>this : Symbol(Test, Decl(neverReturningFunctions1.ts, 63, 1)) +>fail : Symbol(Test.fail, Decl(neverReturningFunctions1.ts, 65, 12)) + + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 78, 7)) + } +} + +function f30(x: string | number | undefined) { +>f30 : Symbol(f30, Decl(neverReturningFunctions1.ts, 83, 1)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 85, 13)) + + if (typeof x === "string") { +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 85, 13)) + + fail(); +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 0, 0)) + + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 85, 13)) + } + else { + x; // number | undefined +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 85, 13)) + + if (x !== undefined) { +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 85, 13)) +>undefined : Symbol(undefined) + + x; // number +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 85, 13)) + + fail(); +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 0, 0)) + + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 85, 13)) + } + else { + x; // undefined +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 85, 13)) + + fail(); +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 0, 0)) + + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 85, 13)) + } + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 85, 13)) + } + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 85, 13)) +} + +function f31(x: { a: string | number }) { +>f31 : Symbol(f31, Decl(neverReturningFunctions1.ts, 105, 1)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 107, 13)) +>a : Symbol(a, Decl(neverReturningFunctions1.ts, 107, 17)) + + if (typeof x.a === "string") { +>x.a : Symbol(a, Decl(neverReturningFunctions1.ts, 107, 17)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 107, 13)) +>a : Symbol(a, Decl(neverReturningFunctions1.ts, 107, 17)) + + fail(); +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 0, 0)) + + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 107, 13)) + + x.a; // Unreachable +>x.a : Symbol(a, Decl(neverReturningFunctions1.ts, 107, 17)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 107, 13)) +>a : Symbol(a, Decl(neverReturningFunctions1.ts, 107, 17)) + } + x; // { a: string | number } +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 107, 13)) + + x.a; // number +>x.a : Symbol(a, Decl(neverReturningFunctions1.ts, 107, 17)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 107, 13)) +>a : Symbol(a, Decl(neverReturningFunctions1.ts, 107, 17)) +} + +function f40(x: number) { +>f40 : Symbol(f40, Decl(neverReturningFunctions1.ts, 115, 1)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 117, 13)) + + try { + x; +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 117, 13)) + + fail(); +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 0, 0)) + + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 117, 13)) + } + finally { + x; +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 117, 13)) + + fail(); +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 0, 0)) + + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 117, 13)) + } + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 117, 13)) +} + +function f41(x: number) { +>f41 : Symbol(f41, Decl(neverReturningFunctions1.ts, 129, 1)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 131, 13)) + + try { + x; +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 131, 13)) + } + finally { + x; +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 131, 13)) + + fail(); +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 0, 0)) + + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 131, 13)) + } + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 131, 13)) +} + +function f42(x: number) { +>f42 : Symbol(f42, Decl(neverReturningFunctions1.ts, 141, 1)) +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 143, 13)) + + try { + x; +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 143, 13)) + + fail(); +>fail : Symbol(fail, Decl(neverReturningFunctions1.ts, 0, 0)) + + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 143, 13)) + } + finally { + x; +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 143, 13)) + } + x; // Unreachable +>x : Symbol(x, Decl(neverReturningFunctions1.ts, 143, 13)) +} + diff --git a/tests/baselines/reference/neverReturningFunctions1.types b/tests/baselines/reference/neverReturningFunctions1.types new file mode 100644 index 00000000000..e7d6afa36a5 --- /dev/null +++ b/tests/baselines/reference/neverReturningFunctions1.types @@ -0,0 +1,439 @@ +=== tests/cases/conformance/controlFlow/neverReturningFunctions1.ts === +function fail(message?: string): never { +>fail : (message?: string | undefined) => never +>message : string | undefined + + throw new Error(message); +>new Error(message) : Error +>Error : ErrorConstructor +>message : string | undefined +} + +function f01(x: string | undefined) { +>f01 : (x: string | undefined) => void +>x : string | undefined + + if (x === undefined) fail("undefined argument"); +>x === undefined : boolean +>x : string | undefined +>undefined : undefined +>fail("undefined argument") : never +>fail : (message?: string | undefined) => never +>"undefined argument" : "undefined argument" + + x.length; // string +>x.length : number +>x : string +>length : number +} + +function f02(x: number): number { +>f02 : (x: number) => number +>x : number + + if (x >= 0) return x; +>x >= 0 : boolean +>x : number +>0 : 0 +>x : number + + fail("negative number"); +>fail("negative number") : never +>fail : (message?: string | undefined) => never +>"negative number" : "negative number" + + x; // Unreachable +>x : number +} + +function f03(x: string) { +>f03 : (x: string) => void +>x : string + + x; // string +>x : string + + fail(); +>fail() : never +>fail : (message?: string | undefined) => never + + x; // Unreachable +>x : string +} + +function f11(x: string | undefined, fail: (message?: string) => never) { +>f11 : (x: string | undefined, fail: (message?: string | undefined) => never) => void +>x : string | undefined +>fail : (message?: string | undefined) => never +>message : string | undefined + + if (x === undefined) fail("undefined argument"); +>x === undefined : boolean +>x : string | undefined +>undefined : undefined +>fail("undefined argument") : never +>fail : (message?: string | undefined) => never +>"undefined argument" : "undefined argument" + + x.length; // string +>x.length : number +>x : string +>length : number +} + +function f12(x: number, fail: (message?: string) => never): number { +>f12 : (x: number, fail: (message?: string | undefined) => never) => number +>x : number +>fail : (message?: string | undefined) => never +>message : string | undefined + + if (x >= 0) return x; +>x >= 0 : boolean +>x : number +>0 : 0 +>x : number + + fail("negative number"); +>fail("negative number") : never +>fail : (message?: string | undefined) => never +>"negative number" : "negative number" + + x; // Unreachable +>x : number +} + +function f13(x: string, fail: (message?: string) => never) { +>f13 : (x: string, fail: (message?: string | undefined) => never) => void +>x : string +>fail : (message?: string | undefined) => never +>message : string | undefined + + x; // string +>x : string + + fail(); +>fail() : never +>fail : (message?: string | undefined) => never + + x; // Unreachable +>x : string +} + +namespace Debug { +>Debug : typeof Debug + + export declare function fail(message?: string): never; +>fail : (message?: string | undefined) => never +>message : string | undefined +} + +function f21(x: string | undefined) { +>f21 : (x: string | undefined) => void +>x : string | undefined + + if (x === undefined) Debug.fail("undefined argument"); +>x === undefined : boolean +>x : string | undefined +>undefined : undefined +>Debug.fail("undefined argument") : never +>Debug.fail : (message?: string | undefined) => never +>Debug : typeof Debug +>fail : (message?: string | undefined) => never +>"undefined argument" : "undefined argument" + + x.length; // string +>x.length : number +>x : string +>length : number +} + +function f22(x: number): number { +>f22 : (x: number) => number +>x : number + + if (x >= 0) return x; +>x >= 0 : boolean +>x : number +>0 : 0 +>x : number + + Debug.fail("negative number"); +>Debug.fail("negative number") : never +>Debug.fail : (message?: string | undefined) => never +>Debug : typeof Debug +>fail : (message?: string | undefined) => never +>"negative number" : "negative number" + + x; // Unreachable +>x : number +} + +function f23(x: string) { +>f23 : (x: string) => void +>x : string + + x; // string +>x : string + + Debug.fail(); +>Debug.fail() : never +>Debug.fail : (message?: string | undefined) => never +>Debug : typeof Debug +>fail : (message?: string | undefined) => never + + x; // Unreachable +>x : string +} + +function f24(x: string) { +>f24 : (x: string) => void +>x : string + + x; // string +>x : string + + ((Debug).fail)(); +>((Debug).fail)() : never +>((Debug).fail) : (message?: string | undefined) => never +>(Debug).fail : (message?: string | undefined) => never +>(Debug) : typeof Debug +>Debug : typeof Debug +>fail : (message?: string | undefined) => never + + x; // Unreachable +>x : string +} + +class Test { +>Test : Test + + fail(message?: string): never { +>fail : (message?: string | undefined) => never +>message : string | undefined + + throw new Error(message); +>new Error(message) : Error +>Error : ErrorConstructor +>message : string | undefined + } + f1(x: string | undefined) { +>f1 : (x: string | undefined) => void +>x : string | undefined + + if (x === undefined) this.fail("undefined argument"); +>x === undefined : boolean +>x : string | undefined +>undefined : undefined +>this.fail("undefined argument") : never +>this.fail : (message?: string | undefined) => never +>this : this +>fail : (message?: string | undefined) => never +>"undefined argument" : "undefined argument" + + x.length; // string +>x.length : number +>x : string +>length : number + } + f2(x: number): number { +>f2 : (x: number) => number +>x : number + + if (x >= 0) return x; +>x >= 0 : boolean +>x : number +>0 : 0 +>x : number + + this.fail("negative number"); +>this.fail("negative number") : never +>this.fail : (message?: string | undefined) => never +>this : this +>fail : (message?: string | undefined) => never +>"negative number" : "negative number" + + x; // Unreachable +>x : number + } + f3(x: string) { +>f3 : (x: string) => void +>x : string + + x; // string +>x : string + + this.fail(); +>this.fail() : never +>this.fail : (message?: string | undefined) => never +>this : this +>fail : (message?: string | undefined) => never + + x; // Unreachable +>x : string + } +} + +function f30(x: string | number | undefined) { +>f30 : (x: string | number | undefined) => void +>x : string | number | undefined + + if (typeof x === "string") { +>typeof x === "string" : boolean +>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>x : string | number | undefined +>"string" : "string" + + fail(); +>fail() : never +>fail : (message?: string | undefined) => never + + x; // Unreachable +>x : string | number | undefined + } + else { + x; // number | undefined +>x : number | undefined + + if (x !== undefined) { +>x !== undefined : boolean +>x : number | undefined +>undefined : undefined + + x; // number +>x : number + + fail(); +>fail() : never +>fail : (message?: string | undefined) => never + + x; // Unreachable +>x : string | number | undefined + } + else { + x; // undefined +>x : undefined + + fail(); +>fail() : never +>fail : (message?: string | undefined) => never + + x; // Unreachable +>x : string | number | undefined + } + x; // Unreachable +>x : string | number | undefined + } + x; // Unreachable +>x : string | number | undefined +} + +function f31(x: { a: string | number }) { +>f31 : (x: { a: string | number; }) => void +>x : { a: string | number; } +>a : string | number + + if (typeof x.a === "string") { +>typeof x.a === "string" : boolean +>typeof x.a : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>x.a : string | number +>x : { a: string | number; } +>a : string | number +>"string" : "string" + + fail(); +>fail() : never +>fail : (message?: string | undefined) => never + + x; // Unreachable +>x : { a: string | number; } + + x.a; // Unreachable +>x.a : string | number +>x : { a: string | number; } +>a : string | number + } + x; // { a: string | number } +>x : { a: string | number; } + + x.a; // number +>x.a : number +>x : { a: string | number; } +>a : number +} + +function f40(x: number) { +>f40 : (x: number) => void +>x : number + + try { + x; +>x : number + + fail(); +>fail() : never +>fail : (message?: string | undefined) => never + + x; // Unreachable +>x : number + } + finally { + x; +>x : number + + fail(); +>fail() : never +>fail : (message?: string | undefined) => never + + x; // Unreachable +>x : number + } + x; // Unreachable +>x : number +} + +function f41(x: number) { +>f41 : (x: number) => void +>x : number + + try { + x; +>x : number + } + finally { + x; +>x : number + + fail(); +>fail() : never +>fail : (message?: string | undefined) => never + + x; // Unreachable +>x : number + } + x; // Unreachable +>x : number +} + +function f42(x: number) { +>f42 : (x: number) => void +>x : number + + try { + x; +>x : number + + fail(); +>fail() : never +>fail : (message?: string | undefined) => never + + x; // Unreachable +>x : number + } + finally { + x; +>x : number + } + x; // Unreachable +>x : number +} +