Address comments

This commit is contained in:
Yui T 2015-12-16 18:13:15 -08:00
parent 319a9cd430
commit 7ad3cb74d4
15 changed files with 86 additions and 52 deletions

View File

@ -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(<ClassLikeDeclaration>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);

View File

@ -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 */

View File

@ -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) {

View File

@ -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'.
~

View File

@ -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;
}

View File

@ -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.
}
}

View File

@ -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();
}
}

View File

@ -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.

View File

@ -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.
}
}

View File

@ -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.
}
}

View File

@ -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.
}
}

View File

@ -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.
}
}

View File

@ -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.
}
}

View File

@ -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.
}
}

View File

@ -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.
}
}