From e15eab9d9961cbd978389e2e0504e366e648f020 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 15 Sep 2015 15:11:04 -0700 Subject: [PATCH 01/12] Add basic check for use super before this Conflicts: src/compiler/diagnosticInformationMap.generated.ts src/compiler/diagnosticMessages.json src/compiler/types.ts --- src/compiler/checker.ts | 13 +++++++++++++ src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/types.ts | 1 + 3 files changed, 18 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7f20c542128..5238a4780e2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6866,6 +6866,11 @@ namespace ts { // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks break; case SyntaxKind.Constructor: + // TODO(yuisu): Comments + if ((container).hasSeenSuperBeforeThis === undefined) { + (container).hasSeenSuperBeforeThis = false; + } + if (isInConstructorArgumentInitializer(node, container)) { error(node, Diagnostics.this_cannot_be_referenced_in_constructor_arguments); // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks @@ -9588,6 +9593,10 @@ namespace ts { const signature = getResolvedSignature(node); if (node.expression.kind === SyntaxKind.SuperKeyword) { + let containgFunction = getContainingFunction(node.expression); + if (containgFunction && containgFunction.kind === SyntaxKind.Constructor && (containgFunction).hasSeenSuperBeforeThis === undefined) { + (containgFunction).hasSeenSuperBeforeThis = true; + } return voidType; } if (node.kind === SyntaxKind.NewExpression) { @@ -11182,6 +11191,10 @@ namespace ts { markThisReferencesAsErrors(superCallStatement.expression); } } + else if (!node.hasSeenSuperBeforeThis) { + // TODO: comment + error(node, Diagnostics.super_has_to_be_called_before_this_accessing); + } } else if (baseConstructorType !== nullType) { error(node, Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 62661706373..51a4e2c6c8f 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2539,5 +2539,9 @@ "A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.": { "category": "Error", "code": 17007 + }, + "'super' has to be called before 'this' accessing.": { + "category": "Error", + "code": 17006 } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f8b26ddaa6d..5a216f8bbcd 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -695,6 +695,7 @@ namespace ts { // @kind(SyntaxKind.Constructor) export interface ConstructorDeclaration extends FunctionLikeDeclaration, ClassElement { body?: FunctionBody; + hasSeenSuperBeforeThis: boolean; // TODDO (yuisu): comment } // For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. From 653deaa2e207b7f4f3e996483a1b6ab61a3fcb65 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 15 Sep 2015 16:42:04 -0700 Subject: [PATCH 02/12] Fix where to report on error. Move from constructor node to just super node Conflicts: src/compiler/checker.ts --- src/compiler/checker.ts | 59 ++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5238a4780e2..b328a4c8366 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6848,6 +6848,22 @@ namespace ts { let container = getThisContainer(node, /* includeArrowFunctions */ true); let needToCaptureLexicalThis = false; + + if (container.kind === SyntaxKind.Constructor) { + // Keep track of whether we have seen "super" before encounter "this" so that + // we can report appropriate error later in checkConstructorDeclaration + // We have to do the check here to make sure we won't give false error when + // "this" is used in arrow functions + // For example: + // constructor() { + // (()=>this); // No Error + // super(); + // } + if ((container).hasSeenSuperBeforeThis === undefined) { + (container).hasSeenSuperBeforeThis = false; + } + } + // Now skip arrow functions to get the "real" owner of 'this'. if (container.kind === SyntaxKind.ArrowFunction) { container = getThisContainer(container, /* includeArrowFunctions */ false); @@ -6866,11 +6882,6 @@ namespace ts { // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks break; case SyntaxKind.Constructor: - // TODO(yuisu): Comments - if ((container).hasSeenSuperBeforeThis === undefined) { - (container).hasSeenSuperBeforeThis = false; - } - if (isInConstructorArgumentInitializer(node, container)) { error(node, Diagnostics.this_cannot_be_referenced_in_constructor_arguments); // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks @@ -11154,8 +11165,25 @@ namespace ts { const containingClassSymbol = getSymbolOfNode(containingClassDecl); const containingClassInstanceType = getDeclaredTypeOfSymbol(containingClassSymbol); const baseConstructorType = getBaseConstructorTypeOfClass(containingClassInstanceType); + const statements = (node.body).statements; + let superCallStatement: ExpressionStatement; + let isSuperCallFirstStatment: boolean; - if (containsSuperCall(node.body)) { + for (const statement of statements) { + if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((statement).expression)) { + superCallStatement = statement; + if (isSuperCallFirstStatment === undefined) { + isSuperCallFirstStatment = true; + } + } + else if (isSuperCallFirstStatment === undefined && !isPrologueDirective(statement)) { + isSuperCallFirstStatment = false; + } + } + + // The main different between looping through each statement in constructor and calling containsSuperCall is that, + // containsSuperCall will consider "super" inside computed-property for inner class declaration + if (superCallStatement || containsSuperCall(node.body)) { if (baseConstructorType === nullType) { error(node, Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null); } @@ -11172,19 +11200,8 @@ namespace ts { // Skip past any prologue directives to find the first statement // to ensure that it was a super call. if (superCallShouldBeFirst) { - const statements = (node.body).statements; - let superCallStatement: ExpressionStatement; - for (const statement of statements) { - if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((statement).expression)) { - superCallStatement = statement; - break; - } - if (!isPrologueDirective(statement)) { - break; - } - } - if (!superCallStatement) { - error(node, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); + if (!isSuperCallFirstStatment) { + error(superCallStatement, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); } else { // In such a required super call, it is a compile-time error for argument expressions to reference this. @@ -11192,8 +11209,8 @@ namespace ts { } } else if (!node.hasSeenSuperBeforeThis) { - // TODO: comment - error(node, Diagnostics.super_has_to_be_called_before_this_accessing); + // In ES6, super inside constructor of class-declaration has to precede "this" accessing + error(superCallStatement, Diagnostics.super_has_to_be_called_before_this_accessing); } } else if (baseConstructorType !== nullType) { From eaa2846348c82d69caf78a50b2efa58e660bdea9 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 15 Sep 2015 17:17:30 -0700 Subject: [PATCH 03/12] Add tests --- .../checkSuperCallBeforeThisAccessing1.ts | 10 ++++++++++ .../checkSuperCallBeforeThisAccessing2.ts | 10 ++++++++++ .../checkSuperCallBeforeThisAccessing3.ts | 15 +++++++++++++++ .../checkSuperCallBeforeThisAccessing4.ts | 19 +++++++++++++++++++ .../checkSuperCallBeforeThisAccessing5.ts | 7 +++++++ .../checkSuperCallBeforeThisAccessing6.ts | 10 ++++++++++ .../checkSuperCallBeforeThisAccessing7.ts | 9 +++++++++ 7 files changed, 80 insertions(+) create mode 100644 tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts create mode 100644 tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts create mode 100644 tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts create mode 100644 tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts create mode 100644 tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts create mode 100644 tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts create mode 100644 tests/cases/compiler/checkSuperCallBeforeThisAccessing7.ts diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts new file mode 100644 index 00000000000..e8dd78ef546 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts @@ -0,0 +1,10 @@ +class Based { } +class Derived extends Based { + public x: number; + constructor() { + super(); + this; + this.x = 10; + var that = this; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts new file mode 100644 index 00000000000..e6545f24288 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts @@ -0,0 +1,10 @@ +class Based { } +class Derived extends Based { + public x: number; + constructor() { + this.x = 100; + super(); + this.x = 10; + var that = this; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts new file mode 100644 index 00000000000..fd9de120b05 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts @@ -0,0 +1,15 @@ +class Based { } +class Derived extends Based { + public x: number; + constructor() { + class innver { + public y: boolean; + constructor() { + this.y = true; + } + } + super(); + this.x = 10; + var that = this; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts new file mode 100644 index 00000000000..1fdee00c2f8 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts @@ -0,0 +1,19 @@ +class Based { } +class Derived extends Based { + public x: number; + constructor() { + (() => { + this; // No error + }); + () => { + this; // No error + }; + (() => { + this; // No error + })(); + super(); + super(); + this.x = 10; + var that = this; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts new file mode 100644 index 00000000000..65d1db6df75 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts @@ -0,0 +1,7 @@ +class Based { constructor(...arg) { } } +class Derived extends Based { + public x: number; + constructor() { + super(this.x); + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts new file mode 100644 index 00000000000..2cdcb9ad3a8 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts @@ -0,0 +1,10 @@ +class Base { + constructor(...arg) { + } +} +class Super extends Base { + constructor() { + (() => this); // No Error + super(); + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing7.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing7.ts new file mode 100644 index 00000000000..1c4af98f0a2 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing7.ts @@ -0,0 +1,9 @@ +class Base { + constructor(func: ()=>Base) { + } +} +class Super extends Base { + constructor() { + super((() => this)); // No error + } +} \ No newline at end of file From c2fb6944041c5d5d3c05cd041518059782839d30 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 15 Sep 2015 17:19:03 -0700 Subject: [PATCH 04/12] Update baselines --- .../checkSuperCallBeforeThisAccessing1.js | 33 +++++++++++ ...checkSuperCallBeforeThisAccessing1.symbols | 28 ++++++++++ .../checkSuperCallBeforeThisAccessing1.types | 31 ++++++++++ ...ckSuperCallBeforeThisAccessing2.errors.txt | 16 ++++++ .../checkSuperCallBeforeThisAccessing2.js | 33 +++++++++++ .../checkSuperCallBeforeThisAccessing3.js | 43 ++++++++++++++ ...checkSuperCallBeforeThisAccessing3.symbols | 38 +++++++++++++ .../checkSuperCallBeforeThisAccessing3.types | 43 ++++++++++++++ .../checkSuperCallBeforeThisAccessing4.js | 52 +++++++++++++++++ ...checkSuperCallBeforeThisAccessing4.symbols | 43 ++++++++++++++ .../checkSuperCallBeforeThisAccessing4.types | 56 +++++++++++++++++++ ...ckSuperCallBeforeThisAccessing5.errors.txt | 13 +++++ .../checkSuperCallBeforeThisAccessing5.js | 31 ++++++++++ .../checkSuperCallBeforeThisAccessing6.js | 36 ++++++++++++ ...checkSuperCallBeforeThisAccessing6.symbols | 20 +++++++ .../checkSuperCallBeforeThisAccessing6.types | 23 ++++++++ .../checkSuperCallBeforeThisAccessing7.js | 30 ++++++++++ ...checkSuperCallBeforeThisAccessing7.symbols | 19 +++++++ .../checkSuperCallBeforeThisAccessing7.types | 22 ++++++++ ...ckSuperCallBeforeThisAccessing8.errors.txt | 16 ++++++ .../checkSuperCallBeforeThisAccessing8.js | 35 ++++++++++++ .../reference/classUpdateTests.errors.txt | 18 ++---- ...derivedClassParameterProperties.errors.txt | 45 ++++++--------- .../derivedClassParameterProperties.js | 4 +- ...rivedClassSuperCallsWithThisArg.errors.txt | 5 +- .../strictModeInConstructor.errors.txt | 12 ++-- .../thisInInvalidContexts.errors.txt | 5 +- .../reference/thisInInvalidContexts.js | 4 +- ...InInvalidContextsExternalModule.errors.txt | 5 +- .../thisInInvalidContextsExternalModule.js | 4 +- .../reference/thisInSuperCall.errors.txt | 7 ++- tests/baselines/reference/thisInSuperCall.js | 4 +- .../reference/thisInSuperCall2.errors.txt | 7 ++- tests/baselines/reference/thisInSuperCall2.js | 4 +- tests/cases/compiler/thisInSuperCall.ts | 2 +- tests/cases/compiler/thisInSuperCall2.ts | 2 +- .../derivedClassParameterProperties.ts | 2 +- .../thisKeyword/thisInInvalidContexts.ts | 2 +- .../thisInInvalidContextsExternalModule.ts | 2 +- 39 files changed, 725 insertions(+), 70 deletions(-) create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing1.symbols create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing3.symbols create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing4.symbols create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing6.symbols create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing7.symbols create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js new file mode 100644 index 00000000000..ec6e6e39ee8 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js @@ -0,0 +1,33 @@ +//// [checkSuperCallBeforeThisAccessing1.ts] +class Based { } +class Derived extends Based { + public x: number; + constructor() { + super(); + this; + this.x = 10; + var that = this; + } +} + +//// [checkSuperCallBeforeThisAccessing1.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Based = (function () { + function Based() { + } + return Based; +})(); +var Derived = (function (_super) { + __extends(Derived, _super); + function Derived() { + _super.call(this); + this; + this.x = 10; + var that = this; + } + return Derived; +})(Based); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.symbols b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.symbols new file mode 100644 index 00000000000..008d1156b56 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.symbols @@ -0,0 +1,28 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts === +class Based { } +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 0)) + +class Derived extends Based { +>Derived : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 15)) +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 0)) + + public x: number; +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing1.ts, 1, 29)) + + constructor() { + super(); +>super : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 0)) + + this; +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 15)) + + this.x = 10; +>this.x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing1.ts, 1, 29)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 15)) +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing1.ts, 1, 29)) + + var that = this; +>that : Symbol(that, Decl(checkSuperCallBeforeThisAccessing1.ts, 7, 11)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 15)) + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types new file mode 100644 index 00000000000..f6114d28997 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types @@ -0,0 +1,31 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts === +class Based { } +>Based : Based + +class Derived extends Based { +>Derived : Derived +>Based : Based + + public x: number; +>x : number + + constructor() { + super(); +>super() : void +>super : typeof Based + + this; +>this : Derived + + this.x = 10; +>this.x = 10 : number +>this.x : number +>this : Derived +>x : number +>10 : number + + var that = this; +>that : Derived +>this : Derived + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt new file mode 100644 index 00000000000..2c9473976a4 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(6,9): error TS17006: 'super' has to be called before 'this' accessing. + + +==== tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts (1 errors) ==== + class Based { } + class Derived extends Based { + public x: number; + constructor() { + this.x = 100; + super(); + ~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. + this.x = 10; + var that = this; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js new file mode 100644 index 00000000000..eb58afd820b --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js @@ -0,0 +1,33 @@ +//// [checkSuperCallBeforeThisAccessing2.ts] +class Based { } +class Derived extends Based { + public x: number; + constructor() { + this.x = 100; + super(); + this.x = 10; + var that = this; + } +} + +//// [checkSuperCallBeforeThisAccessing2.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Based = (function () { + function Based() { + } + return Based; +})(); +var Derived = (function (_super) { + __extends(Derived, _super); + function Derived() { + this.x = 100; + _super.call(this); + this.x = 10; + var that = this; + } + return Derived; +})(Based); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js new file mode 100644 index 00000000000..2c5652cf95f --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js @@ -0,0 +1,43 @@ +//// [checkSuperCallBeforeThisAccessing3.ts] +class Based { } +class Derived extends Based { + public x: number; + constructor() { + class innver { + public y: boolean; + constructor() { + this.y = true; + } + } + super(); + this.x = 10; + var that = this; + } +} + +//// [checkSuperCallBeforeThisAccessing3.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Based = (function () { + function Based() { + } + return Based; +})(); +var Derived = (function (_super) { + __extends(Derived, _super); + function Derived() { + var innver = (function () { + function innver() { + this.y = true; + } + return innver; + })(); + _super.call(this); + this.x = 10; + var that = this; + } + return Derived; +})(Based); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.symbols b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.symbols new file mode 100644 index 00000000000..8dd68fc3b74 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.symbols @@ -0,0 +1,38 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts === +class Based { } +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 0)) + +class Derived extends Based { +>Derived : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 15)) +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 0)) + + public x: number; +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing3.ts, 1, 29)) + + constructor() { + class innver { +>innver : Symbol(innver, Decl(checkSuperCallBeforeThisAccessing3.ts, 3, 19)) + + public y: boolean; +>y : Symbol(y, Decl(checkSuperCallBeforeThisAccessing3.ts, 4, 22)) + + constructor() { + this.y = true; +>this.y : Symbol(y, Decl(checkSuperCallBeforeThisAccessing3.ts, 4, 22)) +>this : Symbol(innver, Decl(checkSuperCallBeforeThisAccessing3.ts, 3, 19)) +>y : Symbol(y, Decl(checkSuperCallBeforeThisAccessing3.ts, 4, 22)) + } + } + super(); +>super : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 0)) + + this.x = 10; +>this.x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing3.ts, 1, 29)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 15)) +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing3.ts, 1, 29)) + + var that = this; +>that : Symbol(that, Decl(checkSuperCallBeforeThisAccessing3.ts, 12, 11)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 15)) + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types new file mode 100644 index 00000000000..45077a6fe5e --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types @@ -0,0 +1,43 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts === +class Based { } +>Based : Based + +class Derived extends Based { +>Derived : Derived +>Based : Based + + public x: number; +>x : number + + constructor() { + class innver { +>innver : innver + + public y: boolean; +>y : boolean + + constructor() { + this.y = true; +>this.y = true : boolean +>this.y : boolean +>this : innver +>y : boolean +>true : boolean + } + } + super(); +>super() : void +>super : typeof Based + + this.x = 10; +>this.x = 10 : number +>this.x : number +>this : Derived +>x : number +>10 : number + + var that = this; +>that : Derived +>this : Derived + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js new file mode 100644 index 00000000000..eacec00c438 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js @@ -0,0 +1,52 @@ +//// [checkSuperCallBeforeThisAccessing4.ts] +class Based { } +class Derived extends Based { + public x: number; + constructor() { + (() => { + this; // No error + }); + () => { + this; // No error + }; + (() => { + this; // No error + })(); + super(); + super(); + this.x = 10; + var that = this; + } +} + +//// [checkSuperCallBeforeThisAccessing4.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Based = (function () { + function Based() { + } + return Based; +})(); +var Derived = (function (_super) { + __extends(Derived, _super); + function Derived() { + var _this = this; + (function () { + _this; // No error + }); + (function () { + _this; // No error + }); + (function () { + _this; // No error + })(); + _super.call(this); + _super.call(this); + this.x = 10; + var that = this; + } + return Derived; +})(Based); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.symbols b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.symbols new file mode 100644 index 00000000000..7101280358d --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.symbols @@ -0,0 +1,43 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts === +class Based { } +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 0)) + +class Derived extends Based { +>Derived : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 0)) + + public x: number; +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing4.ts, 1, 29)) + + constructor() { + (() => { + this; // No error +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) + + }); + () => { + this; // No error +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) + + }; + (() => { + this; // No error +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) + + })(); + super(); +>super : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 0)) + + super(); +>super : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 0)) + + this.x = 10; +>this.x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing4.ts, 1, 29)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing4.ts, 1, 29)) + + var that = this; +>that : Symbol(that, Decl(checkSuperCallBeforeThisAccessing4.ts, 16, 11)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types new file mode 100644 index 00000000000..965d09a4109 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types @@ -0,0 +1,56 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts === +class Based { } +>Based : Based + +class Derived extends Based { +>Derived : Derived +>Based : Based + + public x: number; +>x : number + + constructor() { + (() => { +>(() => { this; // No error }) : () => void +>() => { this; // No error } : () => void + + this; // No error +>this : Derived + + }); + () => { +>() => { this; // No error } : () => void + + this; // No error +>this : Derived + + }; + (() => { +>(() => { this; // No error })() : void +>(() => { this; // No error }) : () => void +>() => { this; // No error } : () => void + + this; // No error +>this : Derived + + })(); + super(); +>super() : void +>super : typeof Based + + super(); +>super() : void +>super : typeof Based + + this.x = 10; +>this.x = 10 : number +>this.x : number +>this : Derived +>x : number +>10 : number + + var that = this; +>that : Derived +>this : Derived + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt new file mode 100644 index 00000000000..fa5cfd524cb --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,9): error TS17006: 'super' has to be called before 'this' accessing. + + +==== tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts (1 errors) ==== + class Based { constructor(...arg) { } } + class Derived extends Based { + public x: number; + constructor() { + super(this.x); + ~~~~~~~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js new file mode 100644 index 00000000000..489c7200050 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js @@ -0,0 +1,31 @@ +//// [checkSuperCallBeforeThisAccessing5.ts] +class Based { constructor(...arg) { } } +class Derived extends Based { + public x: number; + constructor() { + super(this.x); + } +} + +//// [checkSuperCallBeforeThisAccessing5.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Based = (function () { + function Based() { + var arg = []; + for (var _i = 0; _i < arguments.length; _i++) { + arg[_i - 0] = arguments[_i]; + } + } + return Based; +})(); +var Derived = (function (_super) { + __extends(Derived, _super); + function Derived() { + _super.call(this, this.x); + } + return Derived; +})(Based); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js new file mode 100644 index 00000000000..6ad9773bc5f --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js @@ -0,0 +1,36 @@ +//// [checkSuperCallBeforeThisAccessing6.ts] +class Base { + constructor(...arg) { + } +} +class Super extends Base { + constructor() { + (() => this); // No Error + super(); + } +} + +//// [checkSuperCallBeforeThisAccessing6.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Base = (function () { + function Base() { + var arg = []; + for (var _i = 0; _i < arguments.length; _i++) { + arg[_i - 0] = arguments[_i]; + } + } + return Base; +})(); +var Super = (function (_super) { + __extends(Super, _super); + function Super() { + var _this = this; + (function () { return _this; }); // No Error + _super.call(this); + } + return Super; +})(Base); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.symbols b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.symbols new file mode 100644 index 00000000000..84bac5775ec --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.symbols @@ -0,0 +1,20 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts === +class Base { +>Base : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing6.ts, 0, 0)) + + constructor(...arg) { +>arg : Symbol(arg, Decl(checkSuperCallBeforeThisAccessing6.ts, 1, 16)) + } +} +class Super extends Base { +>Super : Symbol(Super, Decl(checkSuperCallBeforeThisAccessing6.ts, 3, 1)) +>Base : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing6.ts, 0, 0)) + + constructor() { + (() => this); // No Error +>this : Symbol(Super, Decl(checkSuperCallBeforeThisAccessing6.ts, 3, 1)) + + super(); +>super : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing6.ts, 0, 0)) + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types new file mode 100644 index 00000000000..8e2d285d85b --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts === +class Base { +>Base : Base + + constructor(...arg) { +>arg : any[] + } +} +class Super extends Base { +>Super : Super +>Base : Base + + constructor() { + (() => this); // No Error +>(() => this) : () => Super +>() => this : () => Super +>this : Super + + super(); +>super() : void +>super : typeof Base + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js new file mode 100644 index 00000000000..eafc662085f --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js @@ -0,0 +1,30 @@ +//// [checkSuperCallBeforeThisAccessing7.ts] +class Base { + constructor(func: ()=>Base) { + } +} +class Super extends Base { + constructor() { + super((() => this)); // No error + } +} + +//// [checkSuperCallBeforeThisAccessing7.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Base = (function () { + function Base(func) { + } + return Base; +})(); +var Super = (function (_super) { + __extends(Super, _super); + function Super() { + var _this = this; + _super.call(this, (function () { return _this; })); // No error + } + return Super; +})(Base); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.symbols b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.symbols new file mode 100644 index 00000000000..3611429d2b2 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing7.ts === +class Base { +>Base : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing7.ts, 0, 0)) + + constructor(func: ()=>Base) { +>func : Symbol(func, Decl(checkSuperCallBeforeThisAccessing7.ts, 1, 16)) +>Base : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing7.ts, 0, 0)) + } +} +class Super extends Base { +>Super : Symbol(Super, Decl(checkSuperCallBeforeThisAccessing7.ts, 3, 1)) +>Base : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing7.ts, 0, 0)) + + constructor() { + super((() => this)); // No error +>super : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing7.ts, 0, 0)) +>this : Symbol(Super, Decl(checkSuperCallBeforeThisAccessing7.ts, 3, 1)) + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types new file mode 100644 index 00000000000..fa5e7dbe857 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing7.ts === +class Base { +>Base : Base + + constructor(func: ()=>Base) { +>func : () => Base +>Base : Base + } +} +class Super extends Base { +>Super : Super +>Base : Base + + constructor() { + super((() => this)); // No error +>super((() => this)) : void +>super : typeof Base +>(() => this) : () => Super +>() => this : () => Super +>this : Super + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt new file mode 100644 index 00000000000..f7c763ee708 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(8,9): error TS17006: 'super' has to be called before 'this' accessing. + + +==== tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts (1 errors) ==== + class Base { + constructor(...arg) { + } + } + class Super extends Base { + constructor() { + var that = this; + super(); + ~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js new file mode 100644 index 00000000000..4675d328b38 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js @@ -0,0 +1,35 @@ +//// [checkSuperCallBeforeThisAccessing8.ts] +class Base { + constructor(...arg) { + } +} +class Super extends Base { + constructor() { + var that = this; + super(); + } +} + +//// [checkSuperCallBeforeThisAccessing8.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Base = (function () { + function Base() { + var arg = []; + for (var _i = 0; _i < arguments.length; _i++) { + arg[_i - 0] = arguments[_i]; + } + } + return Base; +})(); +var Super = (function (_super) { + __extends(Super, _super); + function Super() { + var that = this; + _super.call(this); + } + return Super; +})(Base); diff --git a/tests/baselines/reference/classUpdateTests.errors.txt b/tests/baselines/reference/classUpdateTests.errors.txt index 59e9bc9ced1..55965756410 100644 --- a/tests/baselines/reference/classUpdateTests.errors.txt +++ b/tests/baselines/reference/classUpdateTests.errors.txt @@ -1,11 +1,11 @@ tests/cases/compiler/classUpdateTests.ts(34,2): error TS2377: Constructors for derived classes must contain a 'super' call. tests/cases/compiler/classUpdateTests.ts(43,18): error TS2335: 'super' can only be referenced in a derived class. -tests/cases/compiler/classUpdateTests.ts(57,2): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/compiler/classUpdateTests.ts(59,3): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. tests/cases/compiler/classUpdateTests.ts(63,7): error TS2415: Class 'L' incorrectly extends base class 'G'. Property 'p1' is private in type 'L' but not in type 'G'. tests/cases/compiler/classUpdateTests.ts(69,7): error TS2415: Class 'M' incorrectly extends base class 'G'. Property 'p1' is private in type 'M' but not in type 'G'. -tests/cases/compiler/classUpdateTests.ts(70,2): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/compiler/classUpdateTests.ts(72,3): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. tests/cases/compiler/classUpdateTests.ts(93,3): error TS1128: Declaration or statement expected. tests/cases/compiler/classUpdateTests.ts(95,1): error TS1128: Declaration or statement expected. tests/cases/compiler/classUpdateTests.ts(99,3): error TS1128: Declaration or statement expected. @@ -80,14 +80,11 @@ tests/cases/compiler/classUpdateTests.ts(113,1): error TS1128: Declaration or st class K extends G { constructor(public p1:number) { // ERROR - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var i = 0; - ~~~~~~~~~~~~ super(); - ~~~~~~~~~~ - } - ~~ + ~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + } } class L extends G { @@ -104,14 +101,11 @@ tests/cases/compiler/classUpdateTests.ts(113,1): error TS1128: Declaration or st !!! error TS2415: Class 'M' incorrectly extends base class 'G'. !!! error TS2415: Property 'p1' is private in type 'M' but not in type 'G'. constructor(private p1:number) { // ERROR - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var i = 0; - ~~~~~~~~~~~~ super(); - ~~~~~~~~~~ - } - ~~ + ~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + } } // diff --git a/tests/baselines/reference/derivedClassParameterProperties.errors.txt b/tests/baselines/reference/derivedClassParameterProperties.errors.txt index 0dba0d24cb0..7b57951d493 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.errors.txt +++ b/tests/baselines/reference/derivedClassParameterProperties.errors.txt @@ -1,10 +1,11 @@ -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(15,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(30,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(56,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(79,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(17,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(32,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(49,9): error TS17006: 'super' has to be called before 'this' accessing. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(59,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(82,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. -==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts (4 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts (5 errors) ==== // ordering of super calls in derived constructors matters depending on other class contents class Base { @@ -20,14 +21,11 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP class Derived2 extends Base { constructor(public y: string) { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var a = 1; - ~~~~~~~~~~~~~~~~~~ super(); // error - ~~~~~~~~~~~~~~~~~~~~~~~~~ - } - ~~~~~ + ~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + } } class Derived3 extends Base { @@ -40,14 +38,11 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP class Derived4 extends Base { a = 1; constructor(y: string) { - ~~~~~~~~~~~~~~~~~~~~~~~~ var b = 2; - ~~~~~~~~~~~~~~~~~~ super(); // error - ~~~~~~~~~~~~~~~~~~~~~~~~~ - } - ~~~~~ + ~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + } } class Derived5 extends Base { @@ -63,7 +58,9 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP constructor(y: string) { this.a = 1; var b = 2; - super(); // ok + super(); // error: "super" has to be called before "this" accessing + ~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. } } @@ -71,16 +68,12 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP a = 1; b: number; constructor(y: string) { - ~~~~~~~~~~~~~~~~~~~~~~~~ this.a = 3; - ~~~~~~~~~~~~~~~~~~~ this.b = 3; - ~~~~~~~~~~~~~~~~~~~ super(); // error - ~~~~~~~~~~~~~~~~~~~~~~~~~ - } - ~~~~~ + ~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + } } class Derived8 extends Base { @@ -100,16 +93,12 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP a = 1; b: number; constructor(y: string) { - ~~~~~~~~~~~~~~~~~~~~~~~~ this.a = 3; - ~~~~~~~~~~~~~~~~~~~ this.b = 3; - ~~~~~~~~~~~~~~~~~~~ super(); // error - ~~~~~~~~~~~~~~~~~~~~~~~~~ - } - ~~~~~ + ~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + } } class Derived10 extends Base2 { diff --git a/tests/baselines/reference/derivedClassParameterProperties.js b/tests/baselines/reference/derivedClassParameterProperties.js index 55c0a312b71..0d4a476af12 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.js +++ b/tests/baselines/reference/derivedClassParameterProperties.js @@ -47,7 +47,7 @@ class Derived6 extends Base { constructor(y: string) { this.a = 1; var b = 2; - super(); // ok + super(); // error: "super" has to be called before "this" accessing } } @@ -155,7 +155,7 @@ var Derived6 = (function (_super) { function Derived6(y) { this.a = 1; var b = 2; - _super.call(this); // ok + _super.call(this); // error: "super" has to be called before "this" accessing } return Derived6; })(Base); diff --git a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt index ef43d1d6f52..d8b724e3d0f 100644 --- a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt +++ b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt @@ -1,8 +1,9 @@ +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,9): error TS17006: 'super' has to be called before 'this' accessing. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(14,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(20,21): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts (2 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts (3 errors) ==== class Base { x: string; constructor(a) { } @@ -11,6 +12,8 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS class Derived extends Base { constructor() { super(this); // ok + ~~~~~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. } } diff --git a/tests/baselines/reference/strictModeInConstructor.errors.txt b/tests/baselines/reference/strictModeInConstructor.errors.txt index 9a80732842a..3c38530cc12 100644 --- a/tests/baselines/reference/strictModeInConstructor.errors.txt +++ b/tests/baselines/reference/strictModeInConstructor.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/strictModeInConstructor.ts(27,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/compiler/strictModeInConstructor.ts(29,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. ==== tests/cases/compiler/strictModeInConstructor.ts (1 errors) ==== @@ -29,16 +29,12 @@ tests/cases/compiler/strictModeInConstructor.ts(27,5): error TS2376: A 'super' c public s: number = 9; constructor () { - ~~~~~~~~~~~~~~~~ var x = 1; // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ super(); - ~~~~~~~~~~~~~~~~ - "use strict"; - ~~~~~~~~~~~~~~~~~~~~~ - } - ~~~~~ + ~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + "use strict"; + } } class Bs extends A { diff --git a/tests/baselines/reference/thisInInvalidContexts.errors.txt b/tests/baselines/reference/thisInInvalidContexts.errors.txt index 76b90ed7c20..0200ae6f84c 100644 --- a/tests/baselines/reference/thisInInvalidContexts.errors.txt +++ b/tests/baselines/reference/thisInInvalidContexts.errors.txt @@ -1,4 +1,5 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(14,9): error TS17006: 'super' has to be called before 'this' accessing. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. @@ -23,7 +24,9 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // Error + ~~~~~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. } } diff --git a/tests/baselines/reference/thisInInvalidContexts.js b/tests/baselines/reference/thisInInvalidContexts.js index d5ba69ff536..66cbdb9682c 100644 --- a/tests/baselines/reference/thisInInvalidContexts.js +++ b/tests/baselines/reference/thisInInvalidContexts.js @@ -12,7 +12,7 @@ class ClassWithNoInitializer extends BaseErrClass { t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // Error } } @@ -70,7 +70,7 @@ var ClassWithNoInitializer = (function (_super) { __extends(ClassWithNoInitializer, _super); //'this' in optional super call function ClassWithNoInitializer() { - _super.call(this, this); // OK + _super.call(this, this); // Error } return ClassWithNoInitializer; })(BaseErrClass); diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt index 2aa474d4cdc..ced387a453b 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -1,4 +1,5 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(14,9): error TS17006: 'super' has to be called before 'this' accessing. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. @@ -24,7 +25,9 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // error: "super" has to be called before "this" accessing + ~~~~~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. } } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.js b/tests/baselines/reference/thisInInvalidContextsExternalModule.js index 31a2e995a18..df3abd156de 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.js +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.js @@ -12,7 +12,7 @@ class ClassWithNoInitializer extends BaseErrClass { t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // error: "super" has to be called before "this" accessing } } @@ -71,7 +71,7 @@ var ClassWithNoInitializer = (function (_super) { __extends(ClassWithNoInitializer, _super); //'this' in optional super call function ClassWithNoInitializer() { - _super.call(this, this); // OK + _super.call(this, this); // error: "super" has to be called before "this" accessing } return ClassWithNoInitializer; })(BaseErrClass); diff --git a/tests/baselines/reference/thisInSuperCall.errors.txt b/tests/baselines/reference/thisInSuperCall.errors.txt index 57255aa9582..d0be13d8adc 100644 --- a/tests/baselines/reference/thisInSuperCall.errors.txt +++ b/tests/baselines/reference/thisInSuperCall.errors.txt @@ -1,15 +1,18 @@ +tests/cases/compiler/thisInSuperCall.ts(7,9): error TS17006: 'super' has to be called before 'this' accessing. tests/cases/compiler/thisInSuperCall.ts(14,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/compiler/thisInSuperCall.ts (2 errors) ==== +==== tests/cases/compiler/thisInSuperCall.ts (3 errors) ==== class Base { constructor(x: any) {} } class Foo extends Base { constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing + ~~~~~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. } } diff --git a/tests/baselines/reference/thisInSuperCall.js b/tests/baselines/reference/thisInSuperCall.js index f7d7ca4e4fd..0bcaf35fcbf 100644 --- a/tests/baselines/reference/thisInSuperCall.js +++ b/tests/baselines/reference/thisInSuperCall.js @@ -5,7 +5,7 @@ class Base { class Foo extends Base { constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing } } @@ -36,7 +36,7 @@ var Base = (function () { var Foo = (function (_super) { __extends(Foo, _super); function Foo() { - _super.call(this, this); // no error + _super.call(this, this); // error: "super" has to be called before "this" accessing } return Foo; })(Base); diff --git a/tests/baselines/reference/thisInSuperCall2.errors.txt b/tests/baselines/reference/thisInSuperCall2.errors.txt index d3a94f79487..0559f83eb90 100644 --- a/tests/baselines/reference/thisInSuperCall2.errors.txt +++ b/tests/baselines/reference/thisInSuperCall2.errors.txt @@ -1,7 +1,8 @@ +tests/cases/compiler/thisInSuperCall2.ts(8,9): error TS17006: 'super' has to be called before 'this' accessing. tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/compiler/thisInSuperCall2.ts (1 errors) ==== +==== tests/cases/compiler/thisInSuperCall2.ts (2 errors) ==== class Base { constructor(a: any) {} } @@ -9,7 +10,9 @@ tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be class Foo extends Base { public x: number; constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing + ~~~~~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. } } diff --git a/tests/baselines/reference/thisInSuperCall2.js b/tests/baselines/reference/thisInSuperCall2.js index a9bbeda9fe7..8957a089210 100644 --- a/tests/baselines/reference/thisInSuperCall2.js +++ b/tests/baselines/reference/thisInSuperCall2.js @@ -6,7 +6,7 @@ class Base { class Foo extends Base { public x: number; constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing } } @@ -33,7 +33,7 @@ var Base = (function () { var Foo = (function (_super) { __extends(Foo, _super); function Foo() { - _super.call(this, this); // no error + _super.call(this, this); // error: "super" has to be called before "this" accessing } return Foo; })(Base); diff --git a/tests/cases/compiler/thisInSuperCall.ts b/tests/cases/compiler/thisInSuperCall.ts index 6a54e9ac6f1..b7df7cbafad 100644 --- a/tests/cases/compiler/thisInSuperCall.ts +++ b/tests/cases/compiler/thisInSuperCall.ts @@ -4,7 +4,7 @@ class Base { class Foo extends Base { constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing } } diff --git a/tests/cases/compiler/thisInSuperCall2.ts b/tests/cases/compiler/thisInSuperCall2.ts index 5de7c34cf32..2869ab9a805 100644 --- a/tests/cases/compiler/thisInSuperCall2.ts +++ b/tests/cases/compiler/thisInSuperCall2.ts @@ -5,7 +5,7 @@ class Base { class Foo extends Base { public x: number; constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing } } diff --git a/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts b/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts index edfd7ab4f8c..a054ed0f683 100644 --- a/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts +++ b/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts @@ -46,7 +46,7 @@ class Derived6 extends Base { constructor(y: string) { this.a = 1; var b = 2; - super(); // ok + super(); // error: "super" has to be called before "this" accessing } } diff --git a/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts b/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts index 0afbc450040..2b929318c13 100644 --- a/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts +++ b/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts @@ -11,7 +11,7 @@ class ClassWithNoInitializer extends BaseErrClass { t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // Error } } diff --git a/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts b/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts index 513e56977df..e3d8ce9f5fc 100644 --- a/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts +++ b/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts @@ -11,7 +11,7 @@ class ClassWithNoInitializer extends BaseErrClass { t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // error: "super" has to be called before "this" accessing } } From 680a8932203ea345f74c7e81b87077fab225f128 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 15 Sep 2015 17:19:19 -0700 Subject: [PATCH 05/12] Add tests --- .../compiler/checkSuperCallBeforeThisAccessing8.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts new file mode 100644 index 00000000000..230b40fc24d --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts @@ -0,0 +1,10 @@ +class Base { + constructor(...arg) { + } +} +class Super extends Base { + constructor() { + var that = this; + super(); + } +} \ No newline at end of file From a7688592b2aef3678f10ef246d0f2e49854ae1d1 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 6 Oct 2015 19:46:46 -0700 Subject: [PATCH 06/12] Address PR feedback Conflicts: src/compiler/diagnosticInformationMap.generated.ts src/compiler/diagnosticMessages.json src/compiler/types.ts --- src/compiler/checker.ts | 17 ++++++++++------- src/compiler/diagnosticMessages.json | 4 ++-- src/compiler/types.ts | 3 ++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b328a4c8366..fb47d6bd57c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6859,9 +6859,8 @@ namespace ts { // (()=>this); // No Error // super(); // } - if ((container).hasSeenSuperBeforeThis === undefined) { - (container).hasSeenSuperBeforeThis = false; - } + let nodeLinks = getNodeLinks(container); + nodeLinks.flags |= NodeCheckFlags.HasSeenThisCall; } // Now skip arrow functions to get the "real" owner of 'this'. @@ -9605,8 +9604,12 @@ namespace ts { const signature = getResolvedSignature(node); if (node.expression.kind === SyntaxKind.SuperKeyword) { let containgFunction = getContainingFunction(node.expression); - if (containgFunction && containgFunction.kind === SyntaxKind.Constructor && (containgFunction).hasSeenSuperBeforeThis === undefined) { - (containgFunction).hasSeenSuperBeforeThis = true; + + if (containgFunction && containgFunction.kind === SyntaxKind.Constructor) { + let nodeLinks = getNodeLinks(containgFunction); + if (!(nodeLinks.flags & NodeCheckFlags.HasSeenThisCall)) { + nodeLinks.flags |= NodeCheckFlags.HasSeenSuperBeforeThis; + } } return voidType; } @@ -11208,9 +11211,9 @@ namespace ts { markThisReferencesAsErrors(superCallStatement.expression); } } - else if (!node.hasSeenSuperBeforeThis) { + else if (!(getNodeCheckFlags(node) & NodeCheckFlags.HasSeenSuperBeforeThis)){ // In ES6, super inside constructor of class-declaration has to precede "this" accessing - error(superCallStatement, Diagnostics.super_has_to_be_called_before_this_accessing); + error(superCallStatement, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class); } } else if (baseConstructorType !== nullType) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 51a4e2c6c8f..4bf83bd3e45 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2540,8 +2540,8 @@ "category": "Error", "code": 17007 }, - "'super' has to be called before 'this' accessing.": { + "'super' must be called before accessing 'this' in the constructor of a derived class.": { "category": "Error", - "code": 17006 + "code": 17008 } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5a216f8bbcd..9aded35059a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -695,7 +695,6 @@ namespace ts { // @kind(SyntaxKind.Constructor) export interface ConstructorDeclaration extends FunctionLikeDeclaration, ClassElement { body?: FunctionBody; - hasSeenSuperBeforeThis: boolean; // TODDO (yuisu): comment } // For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. @@ -2031,6 +2030,8 @@ namespace ts { BlockScopedBindingInLoop = 0x00004000, LexicalModuleMergesWithClass = 0x00008000, // Instantiated lexical module declaration is merged with a previous class declaration. LoopWithBlockScopedBindingCapturedInFunction = 0x00010000, // Loop that contains block scoped variable captured in closure + HasSeenSuperBeforeThis = 0x00020000, // Set during the binding if the 'super' is used before 'this' in constructor function + HasSeenThisCall = 0x00040000, // Set during the binding when encounter 'this' } /* @internal */ From c0f818f1a2c0025a0e06983698ee354ffe6ab862 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 6 Oct 2015 19:47:17 -0700 Subject: [PATCH 07/12] Update baseline for new message --- .../reference/checkSuperCallBeforeThisAccessing2.errors.txt | 4 ++-- .../reference/checkSuperCallBeforeThisAccessing5.errors.txt | 4 ++-- .../reference/checkSuperCallBeforeThisAccessing8.errors.txt | 4 ++-- .../reference/derivedClassParameterProperties.errors.txt | 4 ++-- .../reference/derivedClassSuperCallsWithThisArg.errors.txt | 4 ++-- tests/baselines/reference/thisInInvalidContexts.errors.txt | 4 ++-- .../reference/thisInInvalidContextsExternalModule.errors.txt | 4 ++-- tests/baselines/reference/thisInSuperCall.errors.txt | 4 ++-- tests/baselines/reference/thisInSuperCall2.errors.txt | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt index 2c9473976a4..6fdb2e3e394 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(6,9): error TS17006: 'super' has to be called before 'this' accessing. +tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(6,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts (1 errors) ==== @@ -9,7 +9,7 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(6,9): error TS17006: this.x = 100; super(); ~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. this.x = 10; var that = this; } diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt index fa5cfd524cb..edd7745a03c 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,9): error TS17006: 'super' has to be called before 'this' accessing. +tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts (1 errors) ==== @@ -8,6 +8,6 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,9): error TS17006: constructor() { super(this.x); ~~~~~~~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt index f7c763ee708..39db87d41a1 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(8,9): error TS17006: 'super' has to be called before 'this' accessing. +tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(8,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts (1 errors) ==== @@ -11,6 +11,6 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(8,9): error TS17006: var that = this; super(); ~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassParameterProperties.errors.txt b/tests/baselines/reference/derivedClassParameterProperties.errors.txt index 7b57951d493..c5d853dec56 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.errors.txt +++ b/tests/baselines/reference/derivedClassParameterProperties.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(17,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(32,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(49,9): error TS17006: 'super' has to be called before 'this' accessing. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(49,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(59,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(82,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. @@ -60,7 +60,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP var b = 2; super(); // error: "super" has to be called before "this" accessing ~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt index d8b724e3d0f..e72dbe293e9 100644 --- a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt +++ b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,9): error TS17006: 'super' has to be called before 'this' accessing. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(14,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(20,21): error TS2332: 'this' cannot be referenced in current location. @@ -13,7 +13,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS constructor() { super(this); // ok ~~~~~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInInvalidContexts.errors.txt b/tests/baselines/reference/thisInInvalidContexts.errors.txt index 0200ae6f84c..09fa952e2c2 100644 --- a/tests/baselines/reference/thisInInvalidContexts.errors.txt +++ b/tests/baselines/reference/thisInInvalidContexts.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(14,9): error TS17006: 'super' has to be called before 'this' accessing. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(14,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. @@ -26,7 +26,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): constructor() { super(this); // Error ~~~~~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt index ced387a453b..9909c0cbfe9 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(14,9): error TS17006: 'super' has to be called before 'this' accessing. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(14,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. @@ -27,7 +27,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod constructor() { super(this); // error: "super" has to be called before "this" accessing ~~~~~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInSuperCall.errors.txt b/tests/baselines/reference/thisInSuperCall.errors.txt index d0be13d8adc..ea4b6fd742a 100644 --- a/tests/baselines/reference/thisInSuperCall.errors.txt +++ b/tests/baselines/reference/thisInSuperCall.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/thisInSuperCall.ts(7,9): error TS17006: 'super' has to be called before 'this' accessing. +tests/cases/compiler/thisInSuperCall.ts(7,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/thisInSuperCall.ts(14,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be referenced in current location. @@ -12,7 +12,7 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be r constructor() { super(this); // error: "super" has to be called before "this" accessing ~~~~~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInSuperCall2.errors.txt b/tests/baselines/reference/thisInSuperCall2.errors.txt index 0559f83eb90..7130ee8deb8 100644 --- a/tests/baselines/reference/thisInSuperCall2.errors.txt +++ b/tests/baselines/reference/thisInSuperCall2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/thisInSuperCall2.ts(8,9): error TS17006: 'super' has to be called before 'this' accessing. +tests/cases/compiler/thisInSuperCall2.ts(8,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be referenced in current location. @@ -12,7 +12,7 @@ tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be constructor() { super(this); // error: "super" has to be called before "this" accessing ~~~~~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. } } From 319a9cd4309f69e3dcac367eb87e3a1e46dbf6a5 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 30 Nov 2015 10:30:03 -0800 Subject: [PATCH 08/12] Update baseline with new error message number and fix space and comment --- src/compiler/checker.ts | 9 ++++----- src/compiler/types.ts | 2 +- .../checkSuperCallBeforeThisAccessing1.types | 8 ++++---- .../checkSuperCallBeforeThisAccessing2.errors.txt | 4 ++-- .../checkSuperCallBeforeThisAccessing3.types | 8 ++++---- .../checkSuperCallBeforeThisAccessing4.types | 12 ++++++------ .../checkSuperCallBeforeThisAccessing5.errors.txt | 4 ++-- .../checkSuperCallBeforeThisAccessing6.types | 6 +++--- .../checkSuperCallBeforeThisAccessing7.types | 6 +++--- .../checkSuperCallBeforeThisAccessing8.errors.txt | 4 ++-- .../derivedClassParameterProperties.errors.txt | 4 ++-- .../derivedClassSuperCallsWithThisArg.errors.txt | 4 ++-- .../reference/thisInInvalidContexts.errors.txt | 6 +++--- .../thisInInvalidContextsExternalModule.errors.txt | 6 +++--- tests/baselines/reference/thisInSuperCall.errors.txt | 4 ++-- .../baselines/reference/thisInSuperCall2.errors.txt | 4 ++-- 16 files changed, 45 insertions(+), 46 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fb47d6bd57c..0488b1b6dd1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6848,7 +6848,6 @@ namespace ts { let container = getThisContainer(node, /* includeArrowFunctions */ true); let needToCaptureLexicalThis = false; - if (container.kind === SyntaxKind.Constructor) { // Keep track of whether we have seen "super" before encounter "this" so that // we can report appropriate error later in checkConstructorDeclaration @@ -6859,7 +6858,7 @@ namespace ts { // (()=>this); // No Error // super(); // } - let nodeLinks = getNodeLinks(container); + const nodeLinks = getNodeLinks(container); nodeLinks.flags |= NodeCheckFlags.HasSeenThisCall; } @@ -9603,10 +9602,10 @@ namespace ts { const signature = getResolvedSignature(node); if (node.expression.kind === SyntaxKind.SuperKeyword) { - let containgFunction = getContainingFunction(node.expression); + const containgFunction = getContainingFunction(node.expression); if (containgFunction && containgFunction.kind === SyntaxKind.Constructor) { - let nodeLinks = getNodeLinks(containgFunction); + const nodeLinks = getNodeLinks(containgFunction); if (!(nodeLinks.flags & NodeCheckFlags.HasSeenThisCall)) { nodeLinks.flags |= NodeCheckFlags.HasSeenSuperBeforeThis; } @@ -11211,7 +11210,7 @@ namespace ts { markThisReferencesAsErrors(superCallStatement.expression); } } - else if (!(getNodeCheckFlags(node) & NodeCheckFlags.HasSeenSuperBeforeThis)){ + else if (!(getNodeCheckFlags(node) & NodeCheckFlags.HasSeenSuperBeforeThis)) { // In ES6, super inside constructor of class-declaration has to precede "this" accessing error(superCallStatement, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9aded35059a..9a82891df77 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2030,7 +2030,7 @@ namespace ts { BlockScopedBindingInLoop = 0x00004000, LexicalModuleMergesWithClass = 0x00008000, // Instantiated lexical module declaration is merged with a previous class declaration. LoopWithBlockScopedBindingCapturedInFunction = 0x00010000, // Loop that contains block scoped variable captured in closure - HasSeenSuperBeforeThis = 0x00020000, // Set during the binding if the 'super' is used before 'this' in constructor function + HasSeenSuperBeforeThis = 0x00020000, // Set during the binding if 'super' is used before 'this' in constructor function HasSeenThisCall = 0x00040000, // Set during the binding when encounter 'this' } diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types index f6114d28997..d734b0c6ad0 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types @@ -15,17 +15,17 @@ class Derived extends Based { >super : typeof Based this; ->this : Derived +>this : this this.x = 10; >this.x = 10 : number >this.x : number ->this : Derived +>this : this >x : number >10 : number var that = this; ->that : Derived ->this : Derived +>that : this +>this : this } } diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt index 6fdb2e3e394..e48f43c8662 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(6,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(6,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts (1 errors) ==== @@ -9,7 +9,7 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(6,9): error TS17006: this.x = 100; super(); ~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. this.x = 10; var that = this; } diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types index 45077a6fe5e..c4e9e15ed8e 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types @@ -20,7 +20,7 @@ class Derived extends Based { this.y = true; >this.y = true : boolean >this.y : boolean ->this : innver +>this : this >y : boolean >true : boolean } @@ -32,12 +32,12 @@ class Derived extends Based { this.x = 10; >this.x = 10 : number >this.x : number ->this : Derived +>this : this >x : number >10 : number var that = this; ->that : Derived ->this : Derived +>that : this +>this : this } } diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types index 965d09a4109..f42a0ac8563 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types @@ -15,14 +15,14 @@ class Derived extends Based { >() => { this; // No error } : () => void this; // No error ->this : Derived +>this : this }); () => { >() => { this; // No error } : () => void this; // No error ->this : Derived +>this : this }; (() => { @@ -31,7 +31,7 @@ class Derived extends Based { >() => { this; // No error } : () => void this; // No error ->this : Derived +>this : this })(); super(); @@ -45,12 +45,12 @@ class Derived extends Based { this.x = 10; >this.x = 10 : number >this.x : number ->this : Derived +>this : this >x : number >10 : number var that = this; ->that : Derived ->this : Derived +>that : this +>this : this } } diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt index edd7745a03c..1258101cffc 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts (1 errors) ==== @@ -8,6 +8,6 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,9): error TS17006: constructor() { super(this.x); ~~~~~~~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types index 8e2d285d85b..826dab0c400 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types @@ -12,9 +12,9 @@ class Super extends Base { constructor() { (() => this); // No Error ->(() => this) : () => Super ->() => this : () => Super ->this : Super +>(() => this) : () => this +>() => this : () => this +>this : this super(); >super() : void diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types index fa5e7dbe857..11d2ab26d20 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types @@ -15,8 +15,8 @@ class Super extends Base { super((() => this)); // No error >super((() => this)) : void >super : typeof Base ->(() => this) : () => Super ->() => this : () => Super ->this : Super +>(() => this) : () => this +>() => this : () => this +>this : this } } diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt index 39db87d41a1..7a00a4f0130 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(8,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(8,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts (1 errors) ==== @@ -11,6 +11,6 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(8,9): error TS17006: var that = this; super(); ~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassParameterProperties.errors.txt b/tests/baselines/reference/derivedClassParameterProperties.errors.txt index c5d853dec56..37f272db082 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.errors.txt +++ b/tests/baselines/reference/derivedClassParameterProperties.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(17,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(32,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(49,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(49,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(59,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(82,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. @@ -60,7 +60,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP var b = 2; super(); // error: "super" has to be called before "this" accessing ~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt index e72dbe293e9..0190a659166 100644 --- a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt +++ b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(14,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(20,21): error TS2332: 'this' cannot be referenced in current location. @@ -13,7 +13,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS constructor() { super(this); // ok ~~~~~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInInvalidContexts.errors.txt b/tests/baselines/reference/thisInInvalidContexts.errors.txt index 09fa952e2c2..d74db892019 100644 --- a/tests/baselines/reference/thisInInvalidContexts.errors.txt +++ b/tests/baselines/reference/thisInInvalidContexts.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(14,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(14,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. @@ -8,7 +8,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(44,9): tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (7 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (8 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -26,7 +26,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): constructor() { super(this); // Error ~~~~~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt index 9909c0cbfe9..c4188993eee 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(14,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(14,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. @@ -9,7 +9,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(48,1): error TS1148: Cannot compile modules unless the '--module' flag is provided. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (8 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (9 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -27,7 +27,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod constructor() { super(this); // error: "super" has to be called before "this" accessing ~~~~~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInSuperCall.errors.txt b/tests/baselines/reference/thisInSuperCall.errors.txt index ea4b6fd742a..f0fc5854123 100644 --- a/tests/baselines/reference/thisInSuperCall.errors.txt +++ b/tests/baselines/reference/thisInSuperCall.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/thisInSuperCall.ts(7,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/thisInSuperCall.ts(7,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/thisInSuperCall.ts(14,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be referenced in current location. @@ -12,7 +12,7 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be r constructor() { super(this); // error: "super" has to be called before "this" accessing ~~~~~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInSuperCall2.errors.txt b/tests/baselines/reference/thisInSuperCall2.errors.txt index 7130ee8deb8..11ea23d020c 100644 --- a/tests/baselines/reference/thisInSuperCall2.errors.txt +++ b/tests/baselines/reference/thisInSuperCall2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/thisInSuperCall2.ts(8,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/thisInSuperCall2.ts(8,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be referenced in current location. @@ -12,7 +12,7 @@ tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be constructor() { super(this); // error: "super" has to be called before "this" accessing ~~~~~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } From 7ad3cb74d4806a6deb6ea44c5c1a8d5d329ea52e Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 16 Dec 2015 18:13:15 -0800 Subject: [PATCH 09/12] Address comments --- src/compiler/checker.ts | 25 +++++-------------- src/compiler/types.ts | 3 +-- .../baselines/reference/baseCheck.errors.txt | 11 +++++++- tests/baselines/reference/bases.errors.txt | 5 +++- ...ckSuperCallBeforeThisAccessing2.errors.txt | 6 ++--- ...ckSuperCallBeforeThisAccessing5.errors.txt | 4 +-- ...ckSuperCallBeforeThisAccessing8.errors.txt | 6 ++--- ...derivedClassParameterProperties.errors.txt | 20 ++++++++++++--- ...rivedClassSuperCallsWithThisArg.errors.txt | 9 ++++--- .../thisInInvalidContexts.errors.txt | 9 ++++--- ...InInvalidContextsExternalModule.errors.txt | 9 ++++--- .../reference/thisInSuperCall.errors.txt | 12 ++++++--- .../reference/thisInSuperCall1.errors.txt | 5 +++- .../reference/thisInSuperCall2.errors.txt | 9 ++++--- .../reference/thisInSuperCall3.errors.txt | 5 +++- 15 files changed, 86 insertions(+), 52 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0488b1b6dd1..07fdec43c71 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6849,17 +6849,11 @@ namespace ts { let needToCaptureLexicalThis = false; if (container.kind === SyntaxKind.Constructor) { - // Keep track of whether we have seen "super" before encounter "this" so that - // we can report appropriate error later in checkConstructorDeclaration - // We have to do the check here to make sure we won't give false error when - // "this" is used in arrow functions - // For example: - // constructor() { - // (()=>this); // No Error - // super(); - // } - const nodeLinks = getNodeLinks(container); - nodeLinks.flags |= NodeCheckFlags.HasSeenThisCall; + const baseTypeNode = getClassExtendsHeritageClauseElement(container.parent); + if (baseTypeNode && !(getNodeCheckFlags(container) & NodeCheckFlags.HasSeenSuperCall)) { + // In ES6, super inside constructor of class-declaration has to precede "this" accessing + error(node, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class); + } } // Now skip arrow functions to get the "real" owner of 'this'. @@ -9605,10 +9599,7 @@ namespace ts { const containgFunction = getContainingFunction(node.expression); if (containgFunction && containgFunction.kind === SyntaxKind.Constructor) { - const nodeLinks = getNodeLinks(containgFunction); - if (!(nodeLinks.flags & NodeCheckFlags.HasSeenThisCall)) { - nodeLinks.flags |= NodeCheckFlags.HasSeenSuperBeforeThis; - } + getNodeLinks(containgFunction).flags |= NodeCheckFlags.HasSeenSuperCall; } return voidType; } @@ -11210,10 +11201,6 @@ namespace ts { markThisReferencesAsErrors(superCallStatement.expression); } } - else if (!(getNodeCheckFlags(node) & NodeCheckFlags.HasSeenSuperBeforeThis)) { - // In ES6, super inside constructor of class-declaration has to precede "this" accessing - error(superCallStatement, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class); - } } else if (baseConstructorType !== nullType) { error(node, Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9a82891df77..de706229915 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2030,8 +2030,7 @@ namespace ts { BlockScopedBindingInLoop = 0x00004000, LexicalModuleMergesWithClass = 0x00008000, // Instantiated lexical module declaration is merged with a previous class declaration. LoopWithBlockScopedBindingCapturedInFunction = 0x00010000, // Loop that contains block scoped variable captured in closure - HasSeenSuperBeforeThis = 0x00020000, // Set during the binding if 'super' is used before 'this' in constructor function - HasSeenThisCall = 0x00040000, // Set during the binding when encounter 'this' + HasSeenSuperCall = 0x00040000, // Set during the binding when encounter 'super' } /* @internal */ diff --git a/tests/baselines/reference/baseCheck.errors.txt b/tests/baselines/reference/baseCheck.errors.txt index f52ba4b3dbd..0b4e9fd61b1 100644 --- a/tests/baselines/reference/baseCheck.errors.txt +++ b/tests/baselines/reference/baseCheck.errors.txt @@ -1,15 +1,18 @@ tests/cases/compiler/baseCheck.ts(9,18): error TS2304: Cannot find name 'loc'. tests/cases/compiler/baseCheck.ts(17,53): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/baseCheck.ts(17,59): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/baseCheck.ts(17,59): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/baseCheck.ts(18,62): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/baseCheck.ts(18,62): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/baseCheck.ts(19,59): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. tests/cases/compiler/baseCheck.ts(19,68): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/baseCheck.ts(19,68): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/baseCheck.ts(22,9): error TS2304: Cannot find name 'x'. tests/cases/compiler/baseCheck.ts(23,7): error TS2304: Cannot find name 'x'. tests/cases/compiler/baseCheck.ts(26,9): error TS2304: Cannot find name 'x'. -==== tests/cases/compiler/baseCheck.ts (9 errors) ==== +==== tests/cases/compiler/baseCheck.ts (12 errors) ==== class C { constructor(x: number, y: number) { } } class ELoc extends C { constructor(x: number) { @@ -33,14 +36,20 @@ tests/cases/compiler/baseCheck.ts(26,9): error TS2304: Cannot find name 'x'. !!! error TS2346: Supplied parameters do not match any signature of call target. ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. class E extends C { constructor(public z: number) { super(0, this.z) } } ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. class F extends C { constructor(public z: number) { super("hello", this.z) } } // first param type ~~~~~~~ !!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. function f() { if (x<10) { diff --git a/tests/baselines/reference/bases.errors.txt b/tests/baselines/reference/bases.errors.txt index c03a47d7532..7c48c977b2d 100644 --- a/tests/baselines/reference/bases.errors.txt +++ b/tests/baselines/reference/bases.errors.txt @@ -4,6 +4,7 @@ tests/cases/compiler/bases.ts(7,17): error TS2304: Cannot find name 'any'. tests/cases/compiler/bases.ts(11,7): error TS2420: Class 'C' incorrectly implements interface 'I'. Property 'x' is missing in type 'C'. tests/cases/compiler/bases.ts(12,5): error TS2377: Constructors for derived classes must contain a 'super' call. +tests/cases/compiler/bases.ts(13,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/bases.ts(13,14): error TS2339: Property 'x' does not exist on type 'C'. tests/cases/compiler/bases.ts(13,15): error TS1005: ';' expected. tests/cases/compiler/bases.ts(13,17): error TS2304: Cannot find name 'any'. @@ -11,7 +12,7 @@ tests/cases/compiler/bases.ts(17,9): error TS2339: Property 'x' does not exist o tests/cases/compiler/bases.ts(18,9): error TS2339: Property 'y' does not exist on type 'C'. -==== tests/cases/compiler/bases.ts (10 errors) ==== +==== tests/cases/compiler/bases.ts (11 errors) ==== interface I { x; } @@ -36,6 +37,8 @@ tests/cases/compiler/bases.ts(18,9): error TS2339: Property 'y' does not exist o ~~~~~~~~~~~~~~~ this.x: any; ~~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. ~ !!! error TS2339: Property 'x' does not exist on type 'C'. ~ diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt index e48f43c8662..c8aa356fd4f 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(6,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(5,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts (1 errors) ==== @@ -7,9 +7,9 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(6,9): error TS17008: public x: number; constructor() { this.x = 100; - super(); - ~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(); this.x = 10; var that = this; } diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt index 1258101cffc..8ffed5961a3 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts (1 errors) ==== @@ -7,7 +7,7 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,9): error TS17008: public x: number; constructor() { super(this.x); - ~~~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt index 7a00a4f0130..2b37f740331 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(8,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(7,20): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts (1 errors) ==== @@ -9,8 +9,8 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(8,9): error TS17008: class Super extends Base { constructor() { var that = this; - super(); - ~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(); } } \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassParameterProperties.errors.txt b/tests/baselines/reference/derivedClassParameterProperties.errors.txt index 37f272db082..c54ef2a02b7 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.errors.txt +++ b/tests/baselines/reference/derivedClassParameterProperties.errors.txt @@ -1,11 +1,15 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(17,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(32,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(49,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(47,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(57,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(58,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(59,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(80,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(81,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(82,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. -==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts (5 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts (9 errors) ==== // ordering of super calls in derived constructors matters depending on other class contents class Base { @@ -57,10 +61,10 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP a: number; constructor(y: string) { this.a = 1; + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. var b = 2; super(); // error: "super" has to be called before "this" accessing - ~~~~~~~~ -!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -69,7 +73,11 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP b: number; constructor(y: string) { this.a = 3; + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. this.b = 3; + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); // error ~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. @@ -94,7 +102,11 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP b: number; constructor(y: string) { this.a = 3; + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. this.b = 3; + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); // error ~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. diff --git a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt index 0190a659166..7439c81be85 100644 --- a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt +++ b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt @@ -1,9 +1,10 @@ -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(14,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(14,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(20,21): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts (3 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts (4 errors) ==== class Base { x: string; constructor(a) { } @@ -12,7 +13,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS class Derived extends Base { constructor() { super(this); // ok - ~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -22,6 +23,8 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS super(this); // error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInInvalidContexts.errors.txt b/tests/baselines/reference/thisInInvalidContexts.errors.txt index d74db892019..ccf6a015bd9 100644 --- a/tests/baselines/reference/thisInInvalidContexts.errors.txt +++ b/tests/baselines/reference/thisInInvalidContexts.errors.txt @@ -1,6 +1,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(14,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(14,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(38,25): error TS2507: Type 'any' is not a constructor function type. @@ -8,7 +9,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(44,9): tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (8 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (9 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -25,7 +26,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): //'this' in optional super call constructor() { super(this); // Error - ~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -37,6 +38,8 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): super(this); // Error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt index c4188993eee..449f3ede56a 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -1,6 +1,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(14,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(14,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(38,25): error TS2507: Type 'any' is not a constructor function type. @@ -9,7 +10,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(48,1): error TS1148: Cannot compile modules unless the '--module' flag is provided. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (9 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (10 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -26,7 +27,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod //'this' in optional super call constructor() { super(this); // error: "super" has to be called before "this" accessing - ~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -38,6 +39,8 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod super(this); // Error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInSuperCall.errors.txt b/tests/baselines/reference/thisInSuperCall.errors.txt index f0fc5854123..000c2074892 100644 --- a/tests/baselines/reference/thisInSuperCall.errors.txt +++ b/tests/baselines/reference/thisInSuperCall.errors.txt @@ -1,9 +1,11 @@ -tests/cases/compiler/thisInSuperCall.ts(7,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/thisInSuperCall.ts(7,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/thisInSuperCall.ts(14,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall.ts(14,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall.ts(20,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall.ts (3 errors) ==== +==== tests/cases/compiler/thisInSuperCall.ts (5 errors) ==== class Base { constructor(x: any) {} } @@ -11,7 +13,7 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be r class Foo extends Base { constructor() { super(this); // error: "super" has to be called before "this" accessing - ~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -22,6 +24,8 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be r super(this); // error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -30,5 +34,7 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be r super(this); // error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/thisInSuperCall1.errors.txt b/tests/baselines/reference/thisInSuperCall1.errors.txt index 7efc66d1666..98d8ee123ae 100644 --- a/tests/baselines/reference/thisInSuperCall1.errors.txt +++ b/tests/baselines/reference/thisInSuperCall1.errors.txt @@ -1,7 +1,8 @@ tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall1.ts (1 errors) ==== +==== tests/cases/compiler/thisInSuperCall1.ts (2 errors) ==== class Base { constructor(a: any) {} } @@ -11,6 +12,8 @@ tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS2332: 'this' cannot be r super(this); ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/thisInSuperCall2.errors.txt b/tests/baselines/reference/thisInSuperCall2.errors.txt index 11ea23d020c..4047bcb9a06 100644 --- a/tests/baselines/reference/thisInSuperCall2.errors.txt +++ b/tests/baselines/reference/thisInSuperCall2.errors.txt @@ -1,8 +1,9 @@ -tests/cases/compiler/thisInSuperCall2.ts(8,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/thisInSuperCall2.ts(8,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall2.ts (2 errors) ==== +==== tests/cases/compiler/thisInSuperCall2.ts (3 errors) ==== class Base { constructor(a: any) {} } @@ -11,7 +12,7 @@ tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be public x: number; constructor() { super(this); // error: "super" has to be called before "this" accessing - ~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -23,6 +24,8 @@ tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be super(this); // error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/thisInSuperCall3.errors.txt b/tests/baselines/reference/thisInSuperCall3.errors.txt index df5c5f8b5a2..0e7d1575096 100644 --- a/tests/baselines/reference/thisInSuperCall3.errors.txt +++ b/tests/baselines/reference/thisInSuperCall3.errors.txt @@ -1,7 +1,8 @@ tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall3.ts (1 errors) ==== +==== tests/cases/compiler/thisInSuperCall3.ts (2 errors) ==== class Base { constructor(a: any) {} } @@ -13,6 +14,8 @@ tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS2332: 'this' cannot be r super(this); ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file From ce2495f39812ec51402ddb3f8881b5f189eed17c Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 17 Dec 2015 17:21:21 -0800 Subject: [PATCH 10/12] Update baseline from merging master --- .../reference/checkSuperCallBeforeThisAccessing1.js | 4 ++-- .../reference/checkSuperCallBeforeThisAccessing2.js | 4 ++-- .../reference/checkSuperCallBeforeThisAccessing3.js | 6 +++--- .../reference/checkSuperCallBeforeThisAccessing4.js | 4 ++-- .../reference/checkSuperCallBeforeThisAccessing5.js | 4 ++-- .../reference/checkSuperCallBeforeThisAccessing6.js | 4 ++-- .../reference/checkSuperCallBeforeThisAccessing7.js | 4 ++-- .../reference/checkSuperCallBeforeThisAccessing8.js | 4 ++-- .../thisInInvalidContextsExternalModule.errors.txt | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js index ec6e6e39ee8..cfb5726dac1 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js @@ -20,7 +20,7 @@ var Based = (function () { function Based() { } return Based; -})(); +}()); var Derived = (function (_super) { __extends(Derived, _super); function Derived() { @@ -30,4 +30,4 @@ var Derived = (function (_super) { var that = this; } return Derived; -})(Based); +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js index eb58afd820b..afbc15cf912 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js @@ -20,7 +20,7 @@ var Based = (function () { function Based() { } return Based; -})(); +}()); var Derived = (function (_super) { __extends(Derived, _super); function Derived() { @@ -30,4 +30,4 @@ var Derived = (function (_super) { var that = this; } return Derived; -})(Based); +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js index 2c5652cf95f..7e9c23c1f83 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js @@ -25,7 +25,7 @@ var Based = (function () { function Based() { } return Based; -})(); +}()); var Derived = (function (_super) { __extends(Derived, _super); function Derived() { @@ -34,10 +34,10 @@ var Derived = (function (_super) { this.y = true; } return innver; - })(); + }()); _super.call(this); this.x = 10; var that = this; } return Derived; -})(Based); +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js index eacec00c438..1257b446ccb 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js @@ -29,7 +29,7 @@ var Based = (function () { function Based() { } return Based; -})(); +}()); var Derived = (function (_super) { __extends(Derived, _super); function Derived() { @@ -49,4 +49,4 @@ var Derived = (function (_super) { var that = this; } return Derived; -})(Based); +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js index 489c7200050..1889ee998ca 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js @@ -21,11 +21,11 @@ var Based = (function () { } } return Based; -})(); +}()); var Derived = (function (_super) { __extends(Derived, _super); function Derived() { _super.call(this, this.x); } return Derived; -})(Based); +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js index 6ad9773bc5f..39db4dec174 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js @@ -24,7 +24,7 @@ var Base = (function () { } } return Base; -})(); +}()); var Super = (function (_super) { __extends(Super, _super); function Super() { @@ -33,4 +33,4 @@ var Super = (function (_super) { _super.call(this); } return Super; -})(Base); +}(Base)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js index eafc662085f..d071c05db5d 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js @@ -19,7 +19,7 @@ var Base = (function () { function Base(func) { } return Base; -})(); +}()); var Super = (function (_super) { __extends(Super, _super); function Super() { @@ -27,4 +27,4 @@ var Super = (function (_super) { _super.call(this, (function () { return _this; })); // No error } return Super; -})(Base); +}(Base)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js index 4675d328b38..f334cc7f42b 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js @@ -24,7 +24,7 @@ var Base = (function () { } } return Base; -})(); +}()); var Super = (function (_super) { __extends(Super, _super); function Super() { @@ -32,4 +32,4 @@ var Super = (function (_super) { _super.call(this); } return Super; -})(Base); +}(Base)); diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt index 25ee8cbe122..bc671b2fdbe 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -78,4 +78,4 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod export = this; // Should be an error ~~~~~~~~~~~~~~ -!!! error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file. +!!! error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file. \ No newline at end of file From 39c75fd438ba22371be0072effa9fe89731938ce Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 26 Jan 2016 15:34:53 -0800 Subject: [PATCH 11/12] Simplify giving error message and remove unnecessary error --- src/compiler/checker.ts | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 927e00faf8c..e52982576b6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11471,25 +11471,8 @@ namespace ts { const containingClassSymbol = getSymbolOfNode(containingClassDecl); const containingClassInstanceType = getDeclaredTypeOfSymbol(containingClassSymbol); const baseConstructorType = getBaseConstructorTypeOfClass(containingClassInstanceType); - const statements = (node.body).statements; - let superCallStatement: ExpressionStatement; - let isSuperCallFirstStatment: boolean; - for (const statement of statements) { - if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((statement).expression)) { - superCallStatement = statement; - if (isSuperCallFirstStatment === undefined) { - isSuperCallFirstStatment = true; - } - } - else if (isSuperCallFirstStatment === undefined && !isPrologueDirective(statement)) { - isSuperCallFirstStatment = false; - } - } - - // The main different between looping through each statement in constructor and calling containsSuperCall is that, - // containsSuperCall will consider "super" inside computed-property for inner class declaration - if (superCallStatement || containsSuperCall(node.body)) { + if (containsSuperCall(node.body)) { if (baseConstructorType === nullType) { error(node, Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null); } @@ -11506,12 +11489,19 @@ namespace ts { // Skip past any prologue directives to find the first statement // to ensure that it was a super call. if (superCallShouldBeFirst) { - if (!isSuperCallFirstStatment) { - error(superCallStatement, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); + const statements = (node.body).statements; + let superCallStatement: ExpressionStatement; + for (const statement of statements) { + if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((statement).expression)) { + superCallStatement = statement; + break; + } + if (!isPrologueDirective(statement)) { + break; + } } - else { - // In such a required super call, it is a compile-time error for argument expressions to reference this. - markThisReferencesAsErrors(superCallStatement.expression); + if (!superCallStatement) { + error(node, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); } } } From f4290e1538c21baff189b813dcc0e1c64c3f9a71 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 26 Jan 2016 15:37:19 -0800 Subject: [PATCH 12/12] Update baselines --- .../baselines/reference/baseCheck.errors.txt | 11 +----- .../reference/classUpdateTests.errors.txt | 18 ++++++--- ...derivedClassParameterProperties.errors.txt | 38 +++++++++++++------ ...rivedClassSuperCallsWithThisArg.errors.txt | 8 +--- .../strictModeInConstructor.errors.txt | 10 +++-- .../thisInInvalidContexts.errors.txt | 5 +-- ...InInvalidContextsExternalModule.errors.txt | 5 +-- .../reference/thisInSuperCall.errors.txt | 8 +--- .../reference/thisInSuperCall1.errors.txt | 5 +-- .../reference/thisInSuperCall2.errors.txt | 5 +-- .../reference/thisInSuperCall3.errors.txt | 5 +-- 11 files changed, 53 insertions(+), 65 deletions(-) diff --git a/tests/baselines/reference/baseCheck.errors.txt b/tests/baselines/reference/baseCheck.errors.txt index d4af255c972..c31ba95476a 100644 --- a/tests/baselines/reference/baseCheck.errors.txt +++ b/tests/baselines/reference/baseCheck.errors.txt @@ -1,18 +1,15 @@ tests/cases/compiler/baseCheck.ts(9,18): error TS2304: Cannot find name 'loc'. tests/cases/compiler/baseCheck.ts(17,53): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/compiler/baseCheck.ts(17,59): error TS2332: 'this' cannot be referenced in current location. tests/cases/compiler/baseCheck.ts(17,59): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -tests/cases/compiler/baseCheck.ts(18,62): error TS2332: 'this' cannot be referenced in current location. tests/cases/compiler/baseCheck.ts(18,62): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/baseCheck.ts(19,59): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. -tests/cases/compiler/baseCheck.ts(19,68): error TS2332: 'this' cannot be referenced in current location. tests/cases/compiler/baseCheck.ts(19,68): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/baseCheck.ts(22,9): error TS2304: Cannot find name 'x'. tests/cases/compiler/baseCheck.ts(23,7): error TS2304: Cannot find name 'x'. tests/cases/compiler/baseCheck.ts(26,9): error TS2304: Cannot find name 'x'. -==== tests/cases/compiler/baseCheck.ts (12 errors) ==== +==== tests/cases/compiler/baseCheck.ts (9 errors) ==== class C { constructor(x: number, y: number) { } } class ELoc extends C { constructor(x: number) { @@ -35,20 +32,14 @@ tests/cases/compiler/baseCheck.ts(26,9): error TS2304: Cannot find name 'x'. ~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. class E extends C { constructor(public z: number) { super(0, this.z) } } ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. class F extends C { constructor(public z: number) { super("hello", this.z) } } // first param type ~~~~~~~ !!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. function f() { diff --git a/tests/baselines/reference/classUpdateTests.errors.txt b/tests/baselines/reference/classUpdateTests.errors.txt index 55965756410..59e9bc9ced1 100644 --- a/tests/baselines/reference/classUpdateTests.errors.txt +++ b/tests/baselines/reference/classUpdateTests.errors.txt @@ -1,11 +1,11 @@ tests/cases/compiler/classUpdateTests.ts(34,2): error TS2377: Constructors for derived classes must contain a 'super' call. tests/cases/compiler/classUpdateTests.ts(43,18): error TS2335: 'super' can only be referenced in a derived class. -tests/cases/compiler/classUpdateTests.ts(59,3): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/compiler/classUpdateTests.ts(57,2): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. tests/cases/compiler/classUpdateTests.ts(63,7): error TS2415: Class 'L' incorrectly extends base class 'G'. Property 'p1' is private in type 'L' but not in type 'G'. tests/cases/compiler/classUpdateTests.ts(69,7): error TS2415: Class 'M' incorrectly extends base class 'G'. Property 'p1' is private in type 'M' but not in type 'G'. -tests/cases/compiler/classUpdateTests.ts(72,3): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/compiler/classUpdateTests.ts(70,2): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. tests/cases/compiler/classUpdateTests.ts(93,3): error TS1128: Declaration or statement expected. tests/cases/compiler/classUpdateTests.ts(95,1): error TS1128: Declaration or statement expected. tests/cases/compiler/classUpdateTests.ts(99,3): error TS1128: Declaration or statement expected. @@ -80,11 +80,14 @@ tests/cases/compiler/classUpdateTests.ts(113,1): error TS1128: Declaration or st class K extends G { constructor(public p1:number) { // ERROR + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var i = 0; + ~~~~~~~~~~~~ super(); - ~~~~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + ~~~~~~~~~~ } + ~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. } class L extends G { @@ -101,11 +104,14 @@ tests/cases/compiler/classUpdateTests.ts(113,1): error TS1128: Declaration or st !!! error TS2415: Class 'M' incorrectly extends base class 'G'. !!! error TS2415: Property 'p1' is private in type 'M' but not in type 'G'. constructor(private p1:number) { // ERROR + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var i = 0; + ~~~~~~~~~~~~ super(); - ~~~~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + ~~~~~~~~~~ } + ~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. } // diff --git a/tests/baselines/reference/derivedClassParameterProperties.errors.txt b/tests/baselines/reference/derivedClassParameterProperties.errors.txt index fcaae2ecd22..27bb9af63a1 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.errors.txt +++ b/tests/baselines/reference/derivedClassParameterProperties.errors.txt @@ -1,12 +1,12 @@ -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(17,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(32,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(15,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(30,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(47,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(56,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(57,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(58,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(59,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(79,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(80,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(81,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(82,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. ==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts (9 errors) ==== @@ -25,11 +25,14 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP class Derived2 extends Base { constructor(public y: string) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var a = 1; + ~~~~~~~~~~~~~~~~~~ super(); // error - ~~~~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + ~~~~~~~~~~~~~~~~~~~~~~~~~ } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. } class Derived3 extends Base { @@ -42,11 +45,14 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP class Derived4 extends Base { a = 1; constructor(y: string) { + ~~~~~~~~~~~~~~~~~~~~~~~~ var b = 2; + ~~~~~~~~~~~~~~~~~~ super(); // error - ~~~~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + ~~~~~~~~~~~~~~~~~~~~~~~~~ } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. } class Derived5 extends Base { @@ -72,16 +78,20 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP a = 1; b: number; constructor(y: string) { + ~~~~~~~~~~~~~~~~~~~~~~~~ this.a = 3; + ~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. this.b = 3; + ~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); // error - ~~~~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + ~~~~~~~~~~~~~~~~~~~~~~~~~ } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. } class Derived8 extends Base { @@ -101,16 +111,20 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP a = 1; b: number; constructor(y: string) { + ~~~~~~~~~~~~~~~~~~~~~~~~ this.a = 3; + ~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. this.b = 3; + ~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); // error - ~~~~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + ~~~~~~~~~~~~~~~~~~~~~~~~~ } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. } class Derived10 extends Base2 { diff --git a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt index 450d954289a..d381eff17dc 100644 --- a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt +++ b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt @@ -1,10 +1,8 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(14,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(14,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(20,21): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts (4 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts (2 errors) ==== class Base { x: string; constructor(a) { } @@ -22,8 +20,6 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS constructor(public a: string) { super(this); // error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -31,8 +27,6 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS class Derived3 extends Base { constructor(public a: string) { super(() => this); // error - ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. } } diff --git a/tests/baselines/reference/strictModeInConstructor.errors.txt b/tests/baselines/reference/strictModeInConstructor.errors.txt index 3c38530cc12..9a80732842a 100644 --- a/tests/baselines/reference/strictModeInConstructor.errors.txt +++ b/tests/baselines/reference/strictModeInConstructor.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/strictModeInConstructor.ts(29,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/compiler/strictModeInConstructor.ts(27,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. ==== tests/cases/compiler/strictModeInConstructor.ts (1 errors) ==== @@ -29,12 +29,16 @@ tests/cases/compiler/strictModeInConstructor.ts(29,9): error TS2376: A 'super' c public s: number = 9; constructor () { + ~~~~~~~~~~~~~~~~ var x = 1; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ super(); - ~~~~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + ~~~~~~~~~~~~~~~~ "use strict"; + ~~~~~~~~~~~~~~~~~~~~~ } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. } class Bs extends A { diff --git a/tests/baselines/reference/thisInInvalidContexts.errors.txt b/tests/baselines/reference/thisInInvalidContexts.errors.txt index 6e4f665a782..d33260fa108 100644 --- a/tests/baselines/reference/thisInInvalidContexts.errors.txt +++ b/tests/baselines/reference/thisInInvalidContexts.errors.txt @@ -1,6 +1,5 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(14,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. @@ -9,7 +8,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(44,9): tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (9 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (8 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -37,8 +36,6 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): constructor() { super(this); // Error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt index 9c8d4748ed0..6c1a257b5ea 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -1,6 +1,5 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(14,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. @@ -10,7 +9,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(48,1): error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (10 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (9 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -38,8 +37,6 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod constructor() { super(this); // Error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInSuperCall.errors.txt b/tests/baselines/reference/thisInSuperCall.errors.txt index 37a28513cd4..d1eeb1d2b2b 100644 --- a/tests/baselines/reference/thisInSuperCall.errors.txt +++ b/tests/baselines/reference/thisInSuperCall.errors.txt @@ -1,11 +1,9 @@ tests/cases/compiler/thisInSuperCall.ts(7,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -tests/cases/compiler/thisInSuperCall.ts(14,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/compiler/thisInSuperCall.ts(14,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/compiler/thisInSuperCall.ts(20,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall.ts (5 errors) ==== +==== tests/cases/compiler/thisInSuperCall.ts (3 errors) ==== class Base { constructor(x: any) {} } @@ -23,8 +21,6 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS17009: 'super' must be c constructor() { super(this); // error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -33,8 +29,6 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS17009: 'super' must be c constructor(public p) { super(this); // error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/thisInSuperCall1.errors.txt b/tests/baselines/reference/thisInSuperCall1.errors.txt index 752b0d5c0dc..20bc502ab79 100644 --- a/tests/baselines/reference/thisInSuperCall1.errors.txt +++ b/tests/baselines/reference/thisInSuperCall1.errors.txt @@ -1,8 +1,7 @@ -tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall1.ts (2 errors) ==== +==== tests/cases/compiler/thisInSuperCall1.ts (1 errors) ==== class Base { constructor(a: any) {} } @@ -11,8 +10,6 @@ tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS17009: 'super' must be c constructor(public x: number) { super(this); ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInSuperCall2.errors.txt b/tests/baselines/reference/thisInSuperCall2.errors.txt index 8e7d49aa7b9..4e4e9b50a8e 100644 --- a/tests/baselines/reference/thisInSuperCall2.errors.txt +++ b/tests/baselines/reference/thisInSuperCall2.errors.txt @@ -1,9 +1,8 @@ tests/cases/compiler/thisInSuperCall2.ts(8,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall2.ts (3 errors) ==== +==== tests/cases/compiler/thisInSuperCall2.ts (2 errors) ==== class Base { constructor(a: any) {} } @@ -23,8 +22,6 @@ tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS17009: 'super' must be constructor() { super(this); // error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInSuperCall3.errors.txt b/tests/baselines/reference/thisInSuperCall3.errors.txt index dd54d689562..27a7dc8b25d 100644 --- a/tests/baselines/reference/thisInSuperCall3.errors.txt +++ b/tests/baselines/reference/thisInSuperCall3.errors.txt @@ -1,8 +1,7 @@ -tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall3.ts (2 errors) ==== +==== tests/cases/compiler/thisInSuperCall3.ts (1 errors) ==== class Base { constructor(a: any) {} } @@ -13,8 +12,6 @@ tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS17009: 'super' must be c constructor() { super(this); ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } }