|
| 1 | +=== tests/cases/compiler/nestedLoopTypeGuards.ts === |
| 2 | +// Repros from #10378 |
| 3 | + |
| 4 | +function f1() { |
| 5 | +>f1 : Symbol(f1, Decl(nestedLoopTypeGuards.ts, 0, 0)) |
| 6 | + |
| 7 | + var a: boolean | number | string; |
| 8 | +>a : Symbol(a, Decl(nestedLoopTypeGuards.ts, 3, 7)) |
| 9 | + |
| 10 | + if (typeof a !== 'boolean') { |
| 11 | +>a : Symbol(a, Decl(nestedLoopTypeGuards.ts, 3, 7)) |
| 12 | + |
| 13 | + // a is narrowed to "number | string" |
| 14 | + for (var i = 0; i < 1; i++) { |
| 15 | +>i : Symbol(i, Decl(nestedLoopTypeGuards.ts, 6, 16)) |
| 16 | +>i : Symbol(i, Decl(nestedLoopTypeGuards.ts, 6, 16)) |
| 17 | +>i : Symbol(i, Decl(nestedLoopTypeGuards.ts, 6, 16)) |
| 18 | + |
| 19 | + for (var j = 0; j < 1; j++) {} |
| 20 | +>j : Symbol(j, Decl(nestedLoopTypeGuards.ts, 7, 20), Decl(nestedLoopTypeGuards.ts, 10, 24)) |
| 21 | +>j : Symbol(j, Decl(nestedLoopTypeGuards.ts, 7, 20), Decl(nestedLoopTypeGuards.ts, 10, 24)) |
| 22 | +>j : Symbol(j, Decl(nestedLoopTypeGuards.ts, 7, 20), Decl(nestedLoopTypeGuards.ts, 10, 24)) |
| 23 | + |
| 24 | + if (typeof a === 'string') { |
| 25 | +>a : Symbol(a, Decl(nestedLoopTypeGuards.ts, 3, 7)) |
| 26 | + |
| 27 | + // a is narrowed to "string' |
| 28 | + for (var j = 0; j < 1; j++) { |
| 29 | +>j : Symbol(j, Decl(nestedLoopTypeGuards.ts, 7, 20), Decl(nestedLoopTypeGuards.ts, 10, 24)) |
| 30 | +>j : Symbol(j, Decl(nestedLoopTypeGuards.ts, 7, 20), Decl(nestedLoopTypeGuards.ts, 10, 24)) |
| 31 | +>j : Symbol(j, Decl(nestedLoopTypeGuards.ts, 7, 20), Decl(nestedLoopTypeGuards.ts, 10, 24)) |
| 32 | + |
| 33 | + a.length; // Should not error here |
| 34 | +>a.length : Symbol(String.length, Decl(lib.d.ts, --, --)) |
| 35 | +>a : Symbol(a, Decl(nestedLoopTypeGuards.ts, 3, 7)) |
| 36 | +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +function f2() { |
| 44 | +>f2 : Symbol(f2, Decl(nestedLoopTypeGuards.ts, 16, 1)) |
| 45 | + |
| 46 | + var a: string | number; |
| 47 | +>a : Symbol(a, Decl(nestedLoopTypeGuards.ts, 19, 7)) |
| 48 | + |
| 49 | + if (typeof a === 'string') { |
| 50 | +>a : Symbol(a, Decl(nestedLoopTypeGuards.ts, 19, 7)) |
| 51 | + |
| 52 | + while (1) { |
| 53 | + while (1) {} |
| 54 | + if (typeof a === 'string') { |
| 55 | +>a : Symbol(a, Decl(nestedLoopTypeGuards.ts, 19, 7)) |
| 56 | + |
| 57 | + while (1) { |
| 58 | + a.length; // Should not error here |
| 59 | +>a.length : Symbol(String.length, Decl(lib.d.ts, --, --)) |
| 60 | +>a : Symbol(a, Decl(nestedLoopTypeGuards.ts, 19, 7)) |
| 61 | +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments