|
| 1 | +=== tests/cases/compiler/controlFlowNullTypeAndLiteral.ts === |
| 2 | +// Repros from #23771 |
| 3 | + |
| 4 | +const myNull: null = null; |
| 5 | +>myNull : Symbol(myNull, Decl(controlFlowNullTypeAndLiteral.ts, 2, 5)) |
| 6 | + |
| 7 | +const objWithValMaybeNull: { val: number | null } = { val: 1 }; |
| 8 | +>objWithValMaybeNull : Symbol(objWithValMaybeNull, Decl(controlFlowNullTypeAndLiteral.ts, 3, 5)) |
| 9 | +>val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 28)) |
| 10 | +>val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 53)) |
| 11 | + |
| 12 | +const addOne = function (num: number) { |
| 13 | +>addOne : Symbol(addOne, Decl(controlFlowNullTypeAndLiteral.ts, 4, 5)) |
| 14 | +>num : Symbol(num, Decl(controlFlowNullTypeAndLiteral.ts, 4, 25)) |
| 15 | + |
| 16 | + return num + 1; |
| 17 | +>num : Symbol(num, Decl(controlFlowNullTypeAndLiteral.ts, 4, 25)) |
| 18 | +} |
| 19 | + |
| 20 | +if (objWithValMaybeNull.val !== null) |
| 21 | +>objWithValMaybeNull.val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 28)) |
| 22 | +>objWithValMaybeNull : Symbol(objWithValMaybeNull, Decl(controlFlowNullTypeAndLiteral.ts, 3, 5)) |
| 23 | +>val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 28)) |
| 24 | + |
| 25 | + addOne(objWithValMaybeNull.val); |
| 26 | +>addOne : Symbol(addOne, Decl(controlFlowNullTypeAndLiteral.ts, 4, 5)) |
| 27 | +>objWithValMaybeNull.val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 28)) |
| 28 | +>objWithValMaybeNull : Symbol(objWithValMaybeNull, Decl(controlFlowNullTypeAndLiteral.ts, 3, 5)) |
| 29 | +>val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 28)) |
| 30 | + |
| 31 | +if (objWithValMaybeNull.val !== myNull) |
| 32 | +>objWithValMaybeNull.val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 28)) |
| 33 | +>objWithValMaybeNull : Symbol(objWithValMaybeNull, Decl(controlFlowNullTypeAndLiteral.ts, 3, 5)) |
| 34 | +>val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 28)) |
| 35 | +>myNull : Symbol(myNull, Decl(controlFlowNullTypeAndLiteral.ts, 2, 5)) |
| 36 | + |
| 37 | + addOne(objWithValMaybeNull.val); |
| 38 | +>addOne : Symbol(addOne, Decl(controlFlowNullTypeAndLiteral.ts, 4, 5)) |
| 39 | +>objWithValMaybeNull.val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 28)) |
| 40 | +>objWithValMaybeNull : Symbol(objWithValMaybeNull, Decl(controlFlowNullTypeAndLiteral.ts, 3, 5)) |
| 41 | +>val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 28)) |
| 42 | + |
| 43 | +if (objWithValMaybeNull.val === null) |
| 44 | +>objWithValMaybeNull.val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 28)) |
| 45 | +>objWithValMaybeNull : Symbol(objWithValMaybeNull, Decl(controlFlowNullTypeAndLiteral.ts, 3, 5)) |
| 46 | +>val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 28)) |
| 47 | + |
| 48 | + addOne(objWithValMaybeNull.val); // Error |
| 49 | +>addOne : Symbol(addOne, Decl(controlFlowNullTypeAndLiteral.ts, 4, 5)) |
| 50 | +>objWithValMaybeNull.val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 28)) |
| 51 | +>objWithValMaybeNull : Symbol(objWithValMaybeNull, Decl(controlFlowNullTypeAndLiteral.ts, 3, 5)) |
| 52 | +>val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 28)) |
| 53 | + |
| 54 | +if (objWithValMaybeNull.val === myNull) |
| 55 | +>objWithValMaybeNull.val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 28)) |
| 56 | +>objWithValMaybeNull : Symbol(objWithValMaybeNull, Decl(controlFlowNullTypeAndLiteral.ts, 3, 5)) |
| 57 | +>val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 28)) |
| 58 | +>myNull : Symbol(myNull, Decl(controlFlowNullTypeAndLiteral.ts, 2, 5)) |
| 59 | + |
| 60 | + addOne(objWithValMaybeNull.val); // Error |
| 61 | +>addOne : Symbol(addOne, Decl(controlFlowNullTypeAndLiteral.ts, 4, 5)) |
| 62 | +>objWithValMaybeNull.val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 28)) |
| 63 | +>objWithValMaybeNull : Symbol(objWithValMaybeNull, Decl(controlFlowNullTypeAndLiteral.ts, 3, 5)) |
| 64 | +>val : Symbol(val, Decl(controlFlowNullTypeAndLiteral.ts, 3, 28)) |
| 65 | + |
| 66 | +function f(x: number | null) { |
| 67 | +>f : Symbol(f, Decl(controlFlowNullTypeAndLiteral.ts, 16, 36)) |
| 68 | +>x : Symbol(x, Decl(controlFlowNullTypeAndLiteral.ts, 18, 11)) |
| 69 | + |
| 70 | + if(x === myNull) { |
| 71 | +>x : Symbol(x, Decl(controlFlowNullTypeAndLiteral.ts, 18, 11)) |
| 72 | +>myNull : Symbol(myNull, Decl(controlFlowNullTypeAndLiteral.ts, 2, 5)) |
| 73 | + |
| 74 | + const s: string = x; // Error |
| 75 | +>s : Symbol(s, Decl(controlFlowNullTypeAndLiteral.ts, 20, 13)) |
| 76 | +>x : Symbol(x, Decl(controlFlowNullTypeAndLiteral.ts, 18, 11)) |
| 77 | + } |
| 78 | +} |
| 79 | + |
0 commit comments