From db3431e3af4ce7153cf1b29f7aae5fb10b97d6f5 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 5 Apr 2017 11:06:14 -0700 Subject: [PATCH] Add `this` narrowing test and update previous test --- .../cases/compiler/anonymousClassExpression2.ts | 17 +++++++++++++++++ tests/cases/compiler/narrowedConstInMethod.ts | 7 ++++--- 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 tests/cases/compiler/anonymousClassExpression2.ts diff --git a/tests/cases/compiler/anonymousClassExpression2.ts b/tests/cases/compiler/anonymousClassExpression2.ts new file mode 100644 index 00000000000..85095f6a8da --- /dev/null +++ b/tests/cases/compiler/anonymousClassExpression2.ts @@ -0,0 +1,17 @@ +// Fixes #14860 +// note: repros with `while (0);` too +// but it's less inscrutable and more obvious to put it *inside* the loop +while (0) { + class A { + methodA() { + this; //note: a this reference of some kind is required to trigger the bug + } + } + + class B { + methodB() { + this.methodA; // error + this.methodB; // ok + } + } +} diff --git a/tests/cases/compiler/narrowedConstInMethod.ts b/tests/cases/compiler/narrowedConstInMethod.ts index 3ddf97a8df3..14bac690a64 100644 --- a/tests/cases/compiler/narrowedConstInMethod.ts +++ b/tests/cases/compiler/narrowedConstInMethod.ts @@ -1,10 +1,11 @@ // @strictNullChecks: true +// Fixes #10501, possibly null 'x' function f() { const x: string | null = {}; if (x !== null) { return { - bar() { return x.length; } // Error: possibly null x + bar() { return x.length; } // ok }; } } @@ -13,7 +14,7 @@ function f2() { const x: string | null = {}; if (x !== null) { return class { - bar() { return x.length; } // Error: possibly null x + bar() { return x.length; } // ok }; } -} \ No newline at end of file +}