Skip to content

Commit

Permalink
Add regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Oct 7, 2022
1 parent 561ac70 commit fd29a7c
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 0 deletions.
@@ -0,0 +1,25 @@
tests/cases/compiler/exhaustiveSwitchCheckCircularity.ts(14,26): error TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.


==== tests/cases/compiler/exhaustiveSwitchCheckCircularity.ts (1 errors) ====
// Repro from #47539

declare function isNever(n: never): boolean;

function f() {
let foo: "aaa" | "bbb" = "aaa";
while (true) {
switch (foo) {
case "aaa":
}
if (foo === "aaa") {
foo = "bbb";
}
else if (isNever(foo)) { // Error expected
~~~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.
break;
}
}
}

38 changes: 38 additions & 0 deletions tests/baselines/reference/exhaustiveSwitchCheckCircularity.js
@@ -0,0 +1,38 @@
//// [exhaustiveSwitchCheckCircularity.ts]
// Repro from #47539

declare function isNever(n: never): boolean;

function f() {
let foo: "aaa" | "bbb" = "aaa";
while (true) {
switch (foo) {
case "aaa":
}
if (foo === "aaa") {
foo = "bbb";
}
else if (isNever(foo)) { // Error expected
break;
}
}
}


//// [exhaustiveSwitchCheckCircularity.js]
"use strict";
// Repro from #47539
function f() {
var foo = "aaa";
while (true) {
switch (foo) {
case "aaa":
}
if (foo === "aaa") {
foo = "bbb";
}
else if (isNever(foo)) { // Error expected
break;
}
}
}
34 changes: 34 additions & 0 deletions tests/baselines/reference/exhaustiveSwitchCheckCircularity.symbols
@@ -0,0 +1,34 @@
=== tests/cases/compiler/exhaustiveSwitchCheckCircularity.ts ===
// Repro from #47539

declare function isNever(n: never): boolean;
>isNever : Symbol(isNever, Decl(exhaustiveSwitchCheckCircularity.ts, 0, 0))
>n : Symbol(n, Decl(exhaustiveSwitchCheckCircularity.ts, 2, 25))

function f() {
>f : Symbol(f, Decl(exhaustiveSwitchCheckCircularity.ts, 2, 44))

let foo: "aaa" | "bbb" = "aaa";
>foo : Symbol(foo, Decl(exhaustiveSwitchCheckCircularity.ts, 5, 7))

while (true) {
switch (foo) {
>foo : Symbol(foo, Decl(exhaustiveSwitchCheckCircularity.ts, 5, 7))

case "aaa":
}
if (foo === "aaa") {
>foo : Symbol(foo, Decl(exhaustiveSwitchCheckCircularity.ts, 5, 7))

foo = "bbb";
>foo : Symbol(foo, Decl(exhaustiveSwitchCheckCircularity.ts, 5, 7))
}
else if (isNever(foo)) { // Error expected
>isNever : Symbol(isNever, Decl(exhaustiveSwitchCheckCircularity.ts, 0, 0))
>foo : Symbol(foo, Decl(exhaustiveSwitchCheckCircularity.ts, 5, 7))

break;
}
}
}

43 changes: 43 additions & 0 deletions tests/baselines/reference/exhaustiveSwitchCheckCircularity.types
@@ -0,0 +1,43 @@
=== tests/cases/compiler/exhaustiveSwitchCheckCircularity.ts ===
// Repro from #47539

declare function isNever(n: never): boolean;
>isNever : (n: never) => boolean
>n : never

function f() {
>f : () => void

let foo: "aaa" | "bbb" = "aaa";
>foo : "aaa" | "bbb"
>"aaa" : "aaa"

while (true) {
>true : true

switch (foo) {
>foo : "aaa" | "bbb"

case "aaa":
>"aaa" : "aaa"
}
if (foo === "aaa") {
>foo === "aaa" : boolean
>foo : "aaa" | "bbb"
>"aaa" : "aaa"

foo = "bbb";
>foo = "bbb" : "bbb"
>foo : "aaa" | "bbb"
>"bbb" : "bbb"
}
else if (isNever(foo)) { // Error expected
>isNever(foo) : boolean
>isNever : (n: never) => boolean
>foo : "bbb"

break;
}
}
}

20 changes: 20 additions & 0 deletions tests/cases/compiler/exhaustiveSwitchCheckCircularity.ts
@@ -0,0 +1,20 @@
// @strict: true

// Repro from #47539

declare function isNever(n: never): boolean;

function f() {
let foo: "aaa" | "bbb" = "aaa";
while (true) {
switch (foo) {
case "aaa":
}
if (foo === "aaa") {
foo = "bbb";
}
else if (isNever(foo)) { // Error expected
break;
}
}
}

0 comments on commit fd29a7c

Please sign in to comment.