From 87a8d41e11fabfe319b2d4e4f7b27ed3774c63c2 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 18 Nov 2017 11:43:04 -0800 Subject: [PATCH] Accept new baselines --- .../strictPropertyInitialization.errors.txt | 23 +++++++++- .../reference/strictPropertyInitialization.js | 32 +++++++++++++ .../strictPropertyInitialization.symbols | 44 ++++++++++++++++++ .../strictPropertyInitialization.types | 46 +++++++++++++++++++ 4 files changed, 144 insertions(+), 1 deletion(-) diff --git a/tests/baselines/reference/strictPropertyInitialization.errors.txt b/tests/baselines/reference/strictPropertyInitialization.errors.txt index 9dfe2b4ae9..4a3fe0eb3e 100644 --- a/tests/baselines/reference/strictPropertyInitialization.errors.txt +++ b/tests/baselines/reference/strictPropertyInitialization.errors.txt @@ -2,9 +2,11 @@ tests/cases/conformance/classes/propertyMemberDeclarations/strictPropertyInitial tests/cases/conformance/classes/propertyMemberDeclarations/strictPropertyInitialization.ts(6,5): error TS2564: Property 'c' has no initializer and is not definitely assigned in the constructor. tests/cases/conformance/classes/propertyMemberDeclarations/strictPropertyInitialization.ts(48,5): error TS2564: Property 'a' has no initializer and is not definitely assigned in the constructor. tests/cases/conformance/classes/propertyMemberDeclarations/strictPropertyInitialization.ts(71,5): error TS2564: Property 'a' has no initializer and is not definitely assigned in the constructor. +tests/cases/conformance/classes/propertyMemberDeclarations/strictPropertyInitialization.ts(93,22): error TS2565: Property 'a' is used before being assigned. +tests/cases/conformance/classes/propertyMemberDeclarations/strictPropertyInitialization.ts(94,23): error TS2565: Property 'b' is used before being assigned. -==== tests/cases/conformance/classes/propertyMemberDeclarations/strictPropertyInitialization.ts (4 errors) ==== +==== tests/cases/conformance/classes/propertyMemberDeclarations/strictPropertyInitialization.ts (6 errors) ==== // Properties with non-undefined types require initialization class C1 { @@ -96,4 +98,23 @@ tests/cases/conformance/classes/propertyMemberDeclarations/strictPropertyInitial abstract c: number | null; abstract d?: number; } + + // Properties with non-undefined types must be assigned before they can be accessed + // within their constructor + + class C10 { + a: number; + b: number; + c?: number; + constructor() { + let x = this.a; // Error + ~ +!!! error TS2565: Property 'a' is used before being assigned. + this.a = this.b; // Error + ~ +!!! error TS2565: Property 'b' is used before being assigned. + this.b = x; + let y = this.c; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/strictPropertyInitialization.js b/tests/baselines/reference/strictPropertyInitialization.js index 04562b852d..6de5084e40 100644 --- a/tests/baselines/reference/strictPropertyInitialization.js +++ b/tests/baselines/reference/strictPropertyInitialization.js @@ -82,6 +82,21 @@ abstract class C9 { abstract c: number | null; abstract d?: number; } + +// Properties with non-undefined types must be assigned before they can be accessed +// within their constructor + +class C10 { + a: number; + b: number; + c?: number; + constructor() { + let x = this.a; // Error + this.a = this.b; // Error + this.b = x; + let y = this.c; + } +} //// [strictPropertyInitialization.js] @@ -146,6 +161,17 @@ var C9 = /** @class */ (function () { } return C9; }()); +// Properties with non-undefined types must be assigned before they can be accessed +// within their constructor +var C10 = /** @class */ (function () { + function C10() { + var x = this.a; // Error + this.a = this.b; // Error + this.b = x; + var y = this.c; + } + return C10; +}()); //// [strictPropertyInitialization.d.ts] @@ -195,3 +221,9 @@ declare abstract class C9 { abstract c: number | null; abstract d?: number; } +declare class C10 { + a: number; + b: number; + c?: number; + constructor(); +} diff --git a/tests/baselines/reference/strictPropertyInitialization.symbols b/tests/baselines/reference/strictPropertyInitialization.symbols index 684eed916a..3247d975bb 100644 --- a/tests/baselines/reference/strictPropertyInitialization.symbols +++ b/tests/baselines/reference/strictPropertyInitialization.symbols @@ -163,3 +163,47 @@ abstract class C9 { >d : Symbol(C9.d, Decl(strictPropertyInitialization.ts, 80, 30)) } +// Properties with non-undefined types must be assigned before they can be accessed +// within their constructor + +class C10 { +>C10 : Symbol(C10, Decl(strictPropertyInitialization.ts, 82, 1)) + + a: number; +>a : Symbol(C10.a, Decl(strictPropertyInitialization.ts, 87, 11)) + + b: number; +>b : Symbol(C10.b, Decl(strictPropertyInitialization.ts, 88, 14)) + + c?: number; +>c : Symbol(C10.c, Decl(strictPropertyInitialization.ts, 89, 14)) + + constructor() { + let x = this.a; // Error +>x : Symbol(x, Decl(strictPropertyInitialization.ts, 92, 11)) +>this.a : Symbol(C10.a, Decl(strictPropertyInitialization.ts, 87, 11)) +>this : Symbol(C10, Decl(strictPropertyInitialization.ts, 82, 1)) +>a : Symbol(C10.a, Decl(strictPropertyInitialization.ts, 87, 11)) + + this.a = this.b; // Error +>this.a : Symbol(C10.a, Decl(strictPropertyInitialization.ts, 87, 11)) +>this : Symbol(C10, Decl(strictPropertyInitialization.ts, 82, 1)) +>a : Symbol(C10.a, Decl(strictPropertyInitialization.ts, 87, 11)) +>this.b : Symbol(C10.b, Decl(strictPropertyInitialization.ts, 88, 14)) +>this : Symbol(C10, Decl(strictPropertyInitialization.ts, 82, 1)) +>b : Symbol(C10.b, Decl(strictPropertyInitialization.ts, 88, 14)) + + this.b = x; +>this.b : Symbol(C10.b, Decl(strictPropertyInitialization.ts, 88, 14)) +>this : Symbol(C10, Decl(strictPropertyInitialization.ts, 82, 1)) +>b : Symbol(C10.b, Decl(strictPropertyInitialization.ts, 88, 14)) +>x : Symbol(x, Decl(strictPropertyInitialization.ts, 92, 11)) + + let y = this.c; +>y : Symbol(y, Decl(strictPropertyInitialization.ts, 95, 11)) +>this.c : Symbol(C10.c, Decl(strictPropertyInitialization.ts, 89, 14)) +>this : Symbol(C10, Decl(strictPropertyInitialization.ts, 82, 1)) +>c : Symbol(C10.c, Decl(strictPropertyInitialization.ts, 89, 14)) + } +} + diff --git a/tests/baselines/reference/strictPropertyInitialization.types b/tests/baselines/reference/strictPropertyInitialization.types index ad73b895e8..24cbdb14ef 100644 --- a/tests/baselines/reference/strictPropertyInitialization.types +++ b/tests/baselines/reference/strictPropertyInitialization.types @@ -178,3 +178,49 @@ abstract class C9 { >d : number | undefined } +// Properties with non-undefined types must be assigned before they can be accessed +// within their constructor + +class C10 { +>C10 : C10 + + a: number; +>a : number + + b: number; +>b : number + + c?: number; +>c : number | undefined + + constructor() { + let x = this.a; // Error +>x : number +>this.a : number +>this : this +>a : number + + this.a = this.b; // Error +>this.a = this.b : number +>this.a : number +>this : this +>a : number +>this.b : number +>this : this +>b : number + + this.b = x; +>this.b = x : number +>this.b : number +>this : this +>b : number +>x : number + + let y = this.c; +>y : number | undefined +>this.c : number | undefined +>this : this +>c : number | undefined + } +} +