Skip to content

Commit ba521de

Browse files
committed
Accept new baselines
1 parent ce5a3f4 commit ba521de

6 files changed

+362
-0
lines changed

tests/baselines/reference/controlFlowInstanceof.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@ function foo(x: A | undefined) {
7777
x; // A
7878
}
7979
x; // A
80+
}
81+
82+
// X is neither assignable to Y nor a subtype of Y
83+
// Y is assignable to X, but not a subtype of X
84+
85+
interface X {
86+
x?: string;
87+
}
88+
89+
class Y {
90+
y: string;
91+
}
92+
93+
function goo(x: X) {
94+
x;
95+
if (x instanceof Y) {
96+
x.y;
97+
}
98+
x;
8099
}
81100

82101
//// [controlFlowInstanceof.js]
@@ -154,3 +173,12 @@ function foo(x) {
154173
}
155174
x; // A
156175
}
176+
class Y {
177+
}
178+
function goo(x) {
179+
x;
180+
if (x instanceof Y) {
181+
x.y;
182+
}
183+
x;
184+
}

tests/baselines/reference/controlFlowInstanceof.symbols

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,41 @@ function foo(x: A | undefined) {
192192
x; // A
193193
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
194194
}
195+
196+
// X is neither assignable to Y nor a subtype of Y
197+
// Y is assignable to X, but not a subtype of X
198+
199+
interface X {
200+
>X : Symbol(X, Decl(controlFlowInstanceof.ts, 78, 1))
201+
202+
x?: string;
203+
>x : Symbol(X.x, Decl(controlFlowInstanceof.ts, 83, 13))
204+
}
205+
206+
class Y {
207+
>Y : Symbol(Y, Decl(controlFlowInstanceof.ts, 85, 1))
208+
209+
y: string;
210+
>y : Symbol(Y.y, Decl(controlFlowInstanceof.ts, 87, 9))
211+
}
212+
213+
function goo(x: X) {
214+
>goo : Symbol(goo, Decl(controlFlowInstanceof.ts, 89, 1))
215+
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 91, 13))
216+
>X : Symbol(X, Decl(controlFlowInstanceof.ts, 78, 1))
217+
218+
x;
219+
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 91, 13))
220+
221+
if (x instanceof Y) {
222+
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 91, 13))
223+
>Y : Symbol(Y, Decl(controlFlowInstanceof.ts, 85, 1))
224+
225+
x.y;
226+
>x.y : Symbol(Y.y, Decl(controlFlowInstanceof.ts, 87, 9))
227+
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 91, 13))
228+
>y : Symbol(Y.y, Decl(controlFlowInstanceof.ts, 87, 9))
229+
}
230+
x;
231+
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 91, 13))
232+
}

tests/baselines/reference/controlFlowInstanceof.types

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,42 @@ function foo(x: A | undefined) {
215215
x; // A
216216
>x : A
217217
}
218+
219+
// X is neither assignable to Y nor a subtype of Y
220+
// Y is assignable to X, but not a subtype of X
221+
222+
interface X {
223+
>X : X
224+
225+
x?: string;
226+
>x : string
227+
}
228+
229+
class Y {
230+
>Y : Y
231+
232+
y: string;
233+
>y : string
234+
}
235+
236+
function goo(x: X) {
237+
>goo : (x: X) => void
238+
>x : X
239+
>X : X
240+
241+
x;
242+
>x : X
243+
244+
if (x instanceof Y) {
245+
>x instanceof Y : boolean
246+
>x : X
247+
>Y : typeof Y
248+
249+
x.y;
250+
>x.y : string
251+
>x : Y
252+
>y : string
253+
}
254+
x;
255+
>x : X
256+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//// [discriminantsAndTypePredicates.ts]
2+
// Repro from #10145
3+
4+
interface A { type: 'A' }
5+
interface B { type: 'B' }
6+
7+
function isA(x: A | B): x is A { return x.type === 'A'; }
8+
function isB(x: A | B): x is B { return x.type === 'B'; }
9+
10+
function foo1(x: A | B): any {
11+
x; // A | B
12+
if (isA(x)) {
13+
return x; // A
14+
}
15+
x; // B
16+
if (isB(x)) {
17+
return x; // B
18+
}
19+
x; // never
20+
}
21+
22+
function foo2(x: A | B): any {
23+
x; // A | B
24+
if (x.type === 'A') {
25+
return x; // A
26+
}
27+
x; // B
28+
if (x.type === 'B') {
29+
return x; // B
30+
}
31+
x; // never
32+
}
33+
34+
//// [discriminantsAndTypePredicates.js]
35+
// Repro from #10145
36+
function isA(x) { return x.type === 'A'; }
37+
function isB(x) { return x.type === 'B'; }
38+
function foo1(x) {
39+
x; // A | B
40+
if (isA(x)) {
41+
return x; // A
42+
}
43+
x; // B
44+
if (isB(x)) {
45+
return x; // B
46+
}
47+
x; // never
48+
}
49+
function foo2(x) {
50+
x; // A | B
51+
if (x.type === 'A') {
52+
return x; // A
53+
}
54+
x; // B
55+
if (x.type === 'B') {
56+
return x; // B
57+
}
58+
x; // never
59+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
=== tests/cases/compiler/discriminantsAndTypePredicates.ts ===
2+
// Repro from #10145
3+
4+
interface A { type: 'A' }
5+
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
6+
>type : Symbol(A.type, Decl(discriminantsAndTypePredicates.ts, 2, 13))
7+
8+
interface B { type: 'B' }
9+
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
10+
>type : Symbol(B.type, Decl(discriminantsAndTypePredicates.ts, 3, 13))
11+
12+
function isA(x: A | B): x is A { return x.type === 'A'; }
13+
>isA : Symbol(isA, Decl(discriminantsAndTypePredicates.ts, 3, 25))
14+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 5, 13))
15+
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
16+
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
17+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 5, 13))
18+
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
19+
>x.type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
20+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 5, 13))
21+
>type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
22+
23+
function isB(x: A | B): x is B { return x.type === 'B'; }
24+
>isB : Symbol(isB, Decl(discriminantsAndTypePredicates.ts, 5, 57))
25+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 6, 13))
26+
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
27+
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
28+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 6, 13))
29+
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
30+
>x.type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
31+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 6, 13))
32+
>type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
33+
34+
function foo1(x: A | B): any {
35+
>foo1 : Symbol(foo1, Decl(discriminantsAndTypePredicates.ts, 6, 57))
36+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
37+
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
38+
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
39+
40+
x; // A | B
41+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
42+
43+
if (isA(x)) {
44+
>isA : Symbol(isA, Decl(discriminantsAndTypePredicates.ts, 3, 25))
45+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
46+
47+
return x; // A
48+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
49+
}
50+
x; // B
51+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
52+
53+
if (isB(x)) {
54+
>isB : Symbol(isB, Decl(discriminantsAndTypePredicates.ts, 5, 57))
55+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
56+
57+
return x; // B
58+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
59+
}
60+
x; // never
61+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
62+
}
63+
64+
function foo2(x: A | B): any {
65+
>foo2 : Symbol(foo2, Decl(discriminantsAndTypePredicates.ts, 18, 1))
66+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
67+
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
68+
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
69+
70+
x; // A | B
71+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
72+
73+
if (x.type === 'A') {
74+
>x.type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
75+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
76+
>type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
77+
78+
return x; // A
79+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
80+
}
81+
x; // B
82+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
83+
84+
if (x.type === 'B') {
85+
>x.type : Symbol(B.type, Decl(discriminantsAndTypePredicates.ts, 3, 13))
86+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
87+
>type : Symbol(B.type, Decl(discriminantsAndTypePredicates.ts, 3, 13))
88+
89+
return x; // B
90+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
91+
}
92+
x; // never
93+
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
94+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
=== tests/cases/compiler/discriminantsAndTypePredicates.ts ===
2+
// Repro from #10145
3+
4+
interface A { type: 'A' }
5+
>A : A
6+
>type : "A"
7+
8+
interface B { type: 'B' }
9+
>B : B
10+
>type : "B"
11+
12+
function isA(x: A | B): x is A { return x.type === 'A'; }
13+
>isA : (x: A | B) => x is A
14+
>x : A | B
15+
>A : A
16+
>B : B
17+
>x : any
18+
>A : A
19+
>x.type === 'A' : boolean
20+
>x.type : "A" | "B"
21+
>x : A | B
22+
>type : "A" | "B"
23+
>'A' : "A"
24+
25+
function isB(x: A | B): x is B { return x.type === 'B'; }
26+
>isB : (x: A | B) => x is B
27+
>x : A | B
28+
>A : A
29+
>B : B
30+
>x : any
31+
>B : B
32+
>x.type === 'B' : boolean
33+
>x.type : "A" | "B"
34+
>x : A | B
35+
>type : "A" | "B"
36+
>'B' : "B"
37+
38+
function foo1(x: A | B): any {
39+
>foo1 : (x: A | B) => any
40+
>x : A | B
41+
>A : A
42+
>B : B
43+
44+
x; // A | B
45+
>x : A | B
46+
47+
if (isA(x)) {
48+
>isA(x) : boolean
49+
>isA : (x: A | B) => x is A
50+
>x : A | B
51+
52+
return x; // A
53+
>x : A
54+
}
55+
x; // B
56+
>x : B
57+
58+
if (isB(x)) {
59+
>isB(x) : boolean
60+
>isB : (x: A | B) => x is B
61+
>x : B
62+
63+
return x; // B
64+
>x : B
65+
}
66+
x; // never
67+
>x : never
68+
}
69+
70+
function foo2(x: A | B): any {
71+
>foo2 : (x: A | B) => any
72+
>x : A | B
73+
>A : A
74+
>B : B
75+
76+
x; // A | B
77+
>x : A | B
78+
79+
if (x.type === 'A') {
80+
>x.type === 'A' : boolean
81+
>x.type : "A" | "B"
82+
>x : A | B
83+
>type : "A" | "B"
84+
>'A' : "A"
85+
86+
return x; // A
87+
>x : A
88+
}
89+
x; // B
90+
>x : B
91+
92+
if (x.type === 'B') {
93+
>x.type === 'B' : boolean
94+
>x.type : "B"
95+
>x : B
96+
>type : "B"
97+
>'B' : "B"
98+
99+
return x; // B
100+
>x : B
101+
}
102+
x; // never
103+
>x : never
104+
}

0 commit comments

Comments
 (0)