Skip to content

Commit 982abc2

Browse files
committed
Add switch comparability test and update baselines
1 parent 00ebf59 commit 982abc2

7 files changed

+103
-18
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/switchAssignmentCompat.ts(4,10): error TS2678: Type 'typeof Foo' is not comparable to type '0'.
1+
tests/cases/compiler/switchAssignmentCompat.ts(4,10): error TS2678: Type 'typeof Foo' is not comparable to type 'number'.
22

33

44
==== tests/cases/compiler/switchAssignmentCompat.ts (1 errors) ====
@@ -7,6 +7,6 @@ tests/cases/compiler/switchAssignmentCompat.ts(4,10): error TS2678: Type 'typeof
77
switch (0) {
88
case Foo: break; // Error expected
99
~~~
10-
!!! error TS2678: Type 'typeof Foo' is not comparable to type '0'.
10+
!!! error TS2678: Type 'typeof Foo' is not comparable to type 'number'.
1111
}
1212

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
tests/cases/compiler/switchCaseCircularRefeference.ts(5,10): error TS2678: Type '{ a: "A"; b: any; } | { a: "C"; e: any; }' is not comparable to type '"A" | "C"'.
2-
Type '{ a: "C"; e: any; }' is not comparable to type '"A" | "C"'.
3-
Type '{ a: "C"; e: any; }' is not comparable to type '"C"'.
1+
tests/cases/compiler/switchCaseCircularRefeference.ts(5,10): error TS2678: Type '{ a: "A"; b: any; } | { a: "C"; e: any; }' is not comparable to type 'string'.
2+
Type '{ a: "C"; e: any; }' is not comparable to type 'string'.
43

54

65
==== tests/cases/compiler/switchCaseCircularRefeference.ts (1 errors) ====
@@ -10,9 +9,8 @@ tests/cases/compiler/switchCaseCircularRefeference.ts(5,10): error TS2678: Type
109
switch (x.a) {
1110
case x:
1211
~
13-
!!! error TS2678: Type '{ a: "A"; b: any; } | { a: "C"; e: any; }' is not comparable to type '"A" | "C"'.
14-
!!! error TS2678: Type '{ a: "C"; e: any; }' is not comparable to type '"A" | "C"'.
15-
!!! error TS2678: Type '{ a: "C"; e: any; }' is not comparable to type '"C"'.
12+
!!! error TS2678: Type '{ a: "A"; b: any; } | { a: "C"; e: any; }' is not comparable to type 'string'.
13+
!!! error TS2678: Type '{ a: "C"; e: any; }' is not comparable to type 'string'.
1614
break;
1715
}
1816
}

tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1-
tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(4,10): error TS2678: Type 'typeof Foo' is not comparable to type '0'.
2-
tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(5,10): error TS2678: Type '"sss"' is not comparable to type '0'.
3-
tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(6,10): error TS2678: Type '123' is not comparable to type '0'.
4-
tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2678: Type 'true' is not comparable to type '0'.
1+
tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(4,10): error TS2678: Type 'typeof Foo' is not comparable to type 'number'.
2+
tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(5,10): error TS2678: Type 'string' is not comparable to type 'number'.
3+
tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2678: Type 'boolean' is not comparable to type 'number'.
54

65

7-
==== tests/cases/compiler/switchCasesExpressionTypeMismatch.ts (4 errors) ====
6+
==== tests/cases/compiler/switchCasesExpressionTypeMismatch.ts (3 errors) ====
87
class Foo { }
98

109
switch (0) {
1110
case Foo: break; // Error
1211
~~~
13-
!!! error TS2678: Type 'typeof Foo' is not comparable to type '0'.
12+
!!! error TS2678: Type 'typeof Foo' is not comparable to type 'number'.
1413
case "sss": break; // Error
1514
~~~~~
16-
!!! error TS2678: Type '"sss"' is not comparable to type '0'.
15+
!!! error TS2678: Type 'string' is not comparable to type 'number'.
1716
case 123: break; // No Error
18-
~~~
19-
!!! error TS2678: Type '123' is not comparable to type '0'.
2017
case true: break; // Error
2118
~~~~
22-
!!! error TS2678: Type 'true' is not comparable to type '0'.
19+
!!! error TS2678: Type 'boolean' is not comparable to type 'number'.
2320
}
2421

2522
var s: any = 0;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//// [switchComparableCompatForBrands.ts]
2+
class MyBrand
3+
{
4+
private _a: number;
5+
}
6+
7+
function test(strInput: string & MyBrand) {
8+
switch(strInput)
9+
{
10+
case "a":
11+
return 1;
12+
}
13+
return 0;
14+
}
15+
16+
17+
//// [switchComparableCompatForBrands.js]
18+
var MyBrand = (function () {
19+
function MyBrand() {
20+
}
21+
return MyBrand;
22+
}());
23+
function test(strInput) {
24+
switch (strInput) {
25+
case "a":
26+
return 1;
27+
}
28+
return 0;
29+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/compiler/switchComparableCompatForBrands.ts ===
2+
class MyBrand
3+
>MyBrand : Symbol(MyBrand, Decl(switchComparableCompatForBrands.ts, 0, 0))
4+
{
5+
private _a: number;
6+
>_a : Symbol(MyBrand._a, Decl(switchComparableCompatForBrands.ts, 1, 1))
7+
}
8+
9+
function test(strInput: string & MyBrand) {
10+
>test : Symbol(test, Decl(switchComparableCompatForBrands.ts, 3, 1))
11+
>strInput : Symbol(strInput, Decl(switchComparableCompatForBrands.ts, 5, 14))
12+
>MyBrand : Symbol(MyBrand, Decl(switchComparableCompatForBrands.ts, 0, 0))
13+
14+
switch(strInput)
15+
>strInput : Symbol(strInput, Decl(switchComparableCompatForBrands.ts, 5, 14))
16+
{
17+
case "a":
18+
return 1;
19+
}
20+
return 0;
21+
}
22+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/compiler/switchComparableCompatForBrands.ts ===
2+
class MyBrand
3+
>MyBrand : MyBrand
4+
{
5+
private _a: number;
6+
>_a : number
7+
}
8+
9+
function test(strInput: string & MyBrand) {
10+
>test : (strInput: string & MyBrand) => 1 | 0
11+
>strInput : string & MyBrand
12+
>MyBrand : MyBrand
13+
14+
switch(strInput)
15+
>strInput : string & MyBrand
16+
{
17+
case "a":
18+
>"a" : "a"
19+
20+
return 1;
21+
>1 : 1
22+
}
23+
return 0;
24+
>0 : 0
25+
}
26+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class MyBrand
2+
{
3+
private _a: number;
4+
}
5+
6+
function test(strInput: string & MyBrand) {
7+
switch(strInput)
8+
{
9+
case "a":
10+
return 1;
11+
}
12+
return 0;
13+
}

0 commit comments

Comments
 (0)