Skip to content

Commit d9f0293

Browse files
committed
Fixing repro test
1 parent 82d4f42 commit d9f0293

File tree

7 files changed

+128
-184
lines changed

7 files changed

+128
-184
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
tests/cases/compiler/controlFlowLoopAnalysis.ts(13,25): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'.
2+
Type 'undefined' is not assignable to type 'number'.
3+
4+
5+
==== tests/cases/compiler/controlFlowLoopAnalysis.ts (1 errors) ====
6+
7+
// Repro from #8418
8+
9+
let cond: boolean;
10+
11+
function foo(x: number): number { return 1; }
12+
13+
function test1() {
14+
let x: number | undefined;
15+
while (cond) {
16+
while (cond) {
17+
while (cond) {
18+
x = foo(x);
19+
~
20+
!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'.
21+
!!! error TS2345: Type 'undefined' is not assignable to type 'number'.
22+
}
23+
}
24+
x = 1;
25+
}
26+
}
27+
28+
// Repro from #8418
29+
30+
function test2() {
31+
let x: number | undefined;
32+
x = 1;
33+
while (cond) {
34+
while (cond) {
35+
x = foo(x);
36+
}
37+
}
38+
}
39+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//// [controlFlowLoopAnalysis.ts]
2+
3+
// Repro from #8418
4+
5+
let cond: boolean;
6+
7+
function foo(x: number): number { return 1; }
8+
9+
function test1() {
10+
let x: number | undefined;
11+
while (cond) {
12+
while (cond) {
13+
while (cond) {
14+
x = foo(x);
15+
}
16+
}
17+
x = 1;
18+
}
19+
}
20+
21+
// Repro from #8418
22+
23+
function test2() {
24+
let x: number | undefined;
25+
x = 1;
26+
while (cond) {
27+
while (cond) {
28+
x = foo(x);
29+
}
30+
}
31+
}
32+
33+
34+
//// [controlFlowLoopAnalysis.js]
35+
// Repro from #8418
36+
var cond;
37+
function foo(x) { return 1; }
38+
function test1() {
39+
var x;
40+
while (cond) {
41+
while (cond) {
42+
while (cond) {
43+
x = foo(x);
44+
}
45+
}
46+
x = 1;
47+
}
48+
}
49+
// Repro from #8418
50+
function test2() {
51+
var x;
52+
x = 1;
53+
while (cond) {
54+
while (cond) {
55+
x = foo(x);
56+
}
57+
}
58+
}

tests/baselines/reference/controlFlowWhileStatement.js

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,6 @@ function h3() {
105105
}
106106
x; // string | number
107107
}
108-
// Repro for #8418
109-
function foo(x: number): number { return 1; }
110-
function test1() {
111-
let x: number | undefined;
112-
while (cond) {
113-
while (cond) {
114-
while (cond) {
115-
x = foo(x);
116-
}
117-
}
118-
x = 1;
119-
}
120-
}
121-
// Repro for #8418
122-
function test2() {
123-
let x: number | undefined;
124-
x = 1;
125-
while (cond) {
126-
while (cond) {
127-
x = foo(x);
128-
}
129-
}
130-
}
131108

132109

133110
//// [controlFlowWhileStatement.js]
@@ -237,26 +214,3 @@ function h3() {
237214
}
238215
x; // string | number
239216
}
240-
// Repro for #8418
241-
function foo(x) { return 1; }
242-
function test1() {
243-
var x;
244-
while (cond) {
245-
while (cond) {
246-
while (cond) {
247-
x = foo(x);
248-
}
249-
}
250-
x = 1;
251-
}
252-
}
253-
// Repro for #8418
254-
function test2() {
255-
var x;
256-
x = 1;
257-
while (cond) {
258-
while (cond) {
259-
x = foo(x);
260-
}
261-
}
262-
}

tests/baselines/reference/controlFlowWhileStatement.symbols

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -254,57 +254,4 @@ function h3() {
254254
x; // string | number
255255
>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 98, 7))
256256
}
257-
// Repro for #8418
258-
function foo(x: number): number { return 1; }
259-
>foo : Symbol(foo, Decl(controlFlowWhileStatement.ts, 105, 1))
260-
>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 107, 13))
261-
262-
function test1() {
263-
>test1 : Symbol(test1, Decl(controlFlowWhileStatement.ts, 107, 45))
264-
265-
let x: number | undefined;
266-
>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 109, 7))
267-
268-
while (cond) {
269-
>cond : Symbol(cond, Decl(controlFlowWhileStatement.ts, 0, 3))
270-
271-
while (cond) {
272-
>cond : Symbol(cond, Decl(controlFlowWhileStatement.ts, 0, 3))
273-
274-
while (cond) {
275-
>cond : Symbol(cond, Decl(controlFlowWhileStatement.ts, 0, 3))
276-
277-
x = foo(x);
278-
>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 109, 7))
279-
>foo : Symbol(foo, Decl(controlFlowWhileStatement.ts, 105, 1))
280-
>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 109, 7))
281-
}
282-
}
283-
x = 1;
284-
>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 109, 7))
285-
}
286-
}
287-
// Repro for #8418
288-
function test2() {
289-
>test2 : Symbol(test2, Decl(controlFlowWhileStatement.ts, 118, 1))
290-
291-
let x: number | undefined;
292-
>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 121, 7))
293-
294-
x = 1;
295-
>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 121, 7))
296-
297-
while (cond) {
298-
>cond : Symbol(cond, Decl(controlFlowWhileStatement.ts, 0, 3))
299-
300-
while (cond) {
301-
>cond : Symbol(cond, Decl(controlFlowWhileStatement.ts, 0, 3))
302-
303-
x = foo(x);
304-
>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 121, 7))
305-
>foo : Symbol(foo, Decl(controlFlowWhileStatement.ts, 105, 1))
306-
>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 121, 7))
307-
}
308-
}
309-
}
310257

tests/baselines/reference/controlFlowWhileStatement.types

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -307,66 +307,4 @@ function h3() {
307307
x; // string | number
308308
>x : string | number
309309
}
310-
// Repro for #8418
311-
function foo(x: number): number { return 1; }
312-
>foo : (x: number) => number
313-
>x : number
314-
>1 : number
315-
316-
function test1() {
317-
>test1 : () => void
318-
319-
let x: number | undefined;
320-
>x : number
321-
322-
while (cond) {
323-
>cond : boolean
324-
325-
while (cond) {
326-
>cond : boolean
327-
328-
while (cond) {
329-
>cond : boolean
330-
331-
x = foo(x);
332-
>x = foo(x) : number
333-
>x : number
334-
>foo(x) : number
335-
>foo : (x: number) => number
336-
>x : number
337-
}
338-
}
339-
x = 1;
340-
>x = 1 : number
341-
>x : number
342-
>1 : number
343-
}
344-
}
345-
// Repro for #8418
346-
function test2() {
347-
>test2 : () => void
348-
349-
let x: number | undefined;
350-
>x : number
351-
352-
x = 1;
353-
>x = 1 : number
354-
>x : number
355-
>1 : number
356-
357-
while (cond) {
358-
>cond : boolean
359-
360-
while (cond) {
361-
>cond : boolean
362-
363-
x = foo(x);
364-
>x = foo(x) : number
365-
>x : number
366-
>foo(x) : number
367-
>foo : (x: number) => number
368-
>x : number
369-
}
370-
}
371-
}
372310

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// @strictNullChecks: true
2+
3+
// Repro from #8418
4+
5+
let cond: boolean;
6+
7+
function foo(x: number): number { return 1; }
8+
9+
function test1() {
10+
let x: number | undefined;
11+
while (cond) {
12+
while (cond) {
13+
while (cond) {
14+
x = foo(x);
15+
}
16+
}
17+
x = 1;
18+
}
19+
}
20+
21+
// Repro from #8418
22+
23+
function test2() {
24+
let x: number | undefined;
25+
x = 1;
26+
while (cond) {
27+
while (cond) {
28+
x = foo(x);
29+
}
30+
}
31+
}

tests/cases/conformance/controlFlow/controlFlowWhileStatement.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -104,26 +104,3 @@ function h3() {
104104
}
105105
x; // string | number
106106
}
107-
// Repro for #8418
108-
function foo(x: number): number { return 1; }
109-
function test1() {
110-
let x: number | undefined;
111-
while (cond) {
112-
while (cond) {
113-
while (cond) {
114-
x = foo(x);
115-
}
116-
}
117-
x = 1;
118-
}
119-
}
120-
// Repro for #8418
121-
function test2() {
122-
let x: number | undefined;
123-
x = 1;
124-
while (cond) {
125-
while (cond) {
126-
x = foo(x);
127-
}
128-
}
129-
}

0 commit comments

Comments
 (0)