mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 22:51:17 -05:00
Merge pull request #5833 from Microsoft/fix4211
Error when accessing this before super
This commit is contained in:
@@ -7267,6 +7267,14 @@ namespace ts {
|
||||
let container = getThisContainer(node, /* includeArrowFunctions */ true);
|
||||
let needToCaptureLexicalThis = false;
|
||||
|
||||
if (container.kind === SyntaxKind.Constructor) {
|
||||
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'.
|
||||
if (container.kind === SyntaxKind.ArrowFunction) {
|
||||
container = getThisContainer(container, /* includeArrowFunctions */ false);
|
||||
@@ -10213,6 +10221,11 @@ namespace ts {
|
||||
|
||||
const signature = getResolvedSignature(node);
|
||||
if (node.expression.kind === SyntaxKind.SuperKeyword) {
|
||||
const containgFunction = getContainingFunction(node.expression);
|
||||
|
||||
if (containgFunction && containgFunction.kind === SyntaxKind.Constructor) {
|
||||
getNodeLinks(containgFunction).flags |= NodeCheckFlags.HasSeenSuperCall;
|
||||
}
|
||||
return voidType;
|
||||
}
|
||||
if (node.kind === SyntaxKind.NewExpression) {
|
||||
@@ -11830,10 +11843,6 @@ namespace ts {
|
||||
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);
|
||||
}
|
||||
else {
|
||||
// In such a required super call, it is a compile-time error for argument expressions to reference this.
|
||||
markThisReferencesAsErrors(superCallStatement.expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (baseConstructorType !== nullType) {
|
||||
|
||||
@@ -2771,5 +2771,9 @@
|
||||
"JSX element '{0}' has no corresponding closing tag.": {
|
||||
"category": "Error",
|
||||
"code": 17008
|
||||
},
|
||||
"'super' must be called before accessing 'this' in the constructor of a derived class.": {
|
||||
"category": "Error",
|
||||
"code": 17009
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2070,6 +2070,7 @@ namespace ts {
|
||||
LoopWithCapturedBlockScopedBinding = 0x00010000, // Loop that contains block scoped variable captured in closure
|
||||
CapturedBlockScopedBinding = 0x00020000, // Block-scoped binding that is captured in some function
|
||||
BlockScopedBindingInLoop = 0x00040000, // Block-scoped binding with declaration nested inside iteration statement
|
||||
HasSeenSuperCall = 0x00080000, // Set during the binding when encounter 'super'
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
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(18,62): 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 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'.
|
||||
@@ -32,15 +32,15 @@ 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() {
|
||||
if (x<10) {
|
||||
|
||||
@@ -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 TS17009: '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 TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
||||
~
|
||||
!!! error TS2339: Property 'x' does not exist on type 'C'.
|
||||
~
|
||||
|
||||
@@ -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));
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
@@ -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 : this
|
||||
|
||||
this.x = 10;
|
||||
>this.x = 10 : number
|
||||
>this.x : number
|
||||
>this : this
|
||||
>x : number
|
||||
>10 : number
|
||||
|
||||
var that = this;
|
||||
>that : this
|
||||
>this : this
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(5,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
||||
|
||||
|
||||
==== tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts (1 errors) ====
|
||||
class Based { }
|
||||
class Derived extends Based {
|
||||
public x: number;
|
||||
constructor() {
|
||||
this.x = 100;
|
||||
~~~~
|
||||
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
||||
super();
|
||||
this.x = 10;
|
||||
var that = this;
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
@@ -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 : this
|
||||
>y : boolean
|
||||
>true : boolean
|
||||
}
|
||||
}
|
||||
super();
|
||||
>super() : void
|
||||
>super : typeof Based
|
||||
|
||||
this.x = 10;
|
||||
>this.x = 10 : number
|
||||
>this.x : number
|
||||
>this : this
|
||||
>x : number
|
||||
>10 : number
|
||||
|
||||
var that = this;
|
||||
>that : this
|
||||
>this : this
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
@@ -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 : this
|
||||
|
||||
});
|
||||
() => {
|
||||
>() => { this; // No error } : () => void
|
||||
|
||||
this; // No error
|
||||
>this : this
|
||||
|
||||
};
|
||||
(() => {
|
||||
>(() => { this; // No error })() : void
|
||||
>(() => { this; // No error }) : () => void
|
||||
>() => { this; // No error } : () => void
|
||||
|
||||
this; // No error
|
||||
>this : this
|
||||
|
||||
})();
|
||||
super();
|
||||
>super() : void
|
||||
>super : typeof Based
|
||||
|
||||
super();
|
||||
>super() : void
|
||||
>super : typeof Based
|
||||
|
||||
this.x = 10;
|
||||
>this.x = 10 : number
|
||||
>this.x : number
|
||||
>this : this
|
||||
>x : number
|
||||
>10 : number
|
||||
|
||||
var that = this;
|
||||
>that : this
|
||||
>this : this
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
||||
|
||||
|
||||
==== tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts (1 errors) ====
|
||||
class Based { constructor(...arg) { } }
|
||||
class Derived extends Based {
|
||||
public x: number;
|
||||
constructor() {
|
||||
super(this.x);
|
||||
~~~~
|
||||
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
@@ -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) : () => this
|
||||
>() => this : () => this
|
||||
>this : this
|
||||
|
||||
super();
|
||||
>super() : void
|
||||
>super : typeof Base
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
@@ -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) : () => this
|
||||
>() => this : () => this
|
||||
>this : this
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(7,20): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
||||
|
||||
|
||||
==== tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts (1 errors) ====
|
||||
class Base {
|
||||
constructor(...arg) {
|
||||
}
|
||||
}
|
||||
class Super extends Base {
|
||||
constructor() {
|
||||
var that = this;
|
||||
~~~~
|
||||
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
@@ -1,10 +1,15 @@
|
||||
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(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 (4 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 {
|
||||
@@ -62,8 +67,10 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP
|
||||
a: number;
|
||||
constructor(y: string) {
|
||||
this.a = 1;
|
||||
~~~~
|
||||
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
||||
var b = 2;
|
||||
super(); // ok
|
||||
super(); // error: "super" has to be called before "this" accessing
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,8 +81,12 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
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
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
}
|
||||
@@ -103,8 +114,12 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
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
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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(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 TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
||||
|
||||
|
||||
==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts (2 errors) ====
|
||||
@@ -11,6 +11,8 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS
|
||||
class Derived extends Base {
|
||||
constructor() {
|
||||
super(this); // ok
|
||||
~~~~
|
||||
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,15 +20,13 @@ 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.
|
||||
}
|
||||
}
|
||||
|
||||
class Derived3 extends Base {
|
||||
constructor(public a: string) {
|
||||
super(() => this); // error
|
||||
~~~~
|
||||
!!! error TS2332: 'this' cannot be referenced in current location.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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(22,15): error TS2332: 'this' cannot be referenced in current location.
|
||||
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 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.
|
||||
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(38,25): error TS2507: Type 'any' is not a constructor function type.
|
||||
@@ -7,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
|
||||
@@ -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 TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +36,7 @@ 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.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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(22,15): error TS2332: 'this' cannot be referenced in current location.
|
||||
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 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.
|
||||
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(38,25): error TS2507: Type 'any' is not a constructor function type.
|
||||
@@ -8,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 (8 errors) ====
|
||||
==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (9 errors) ====
|
||||
//'this' in static member initializer
|
||||
class ErrClass1 {
|
||||
static t = this; // Error
|
||||
@@ -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 TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +37,7 @@ 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.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
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(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 TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
||||
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 (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 TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +21,7 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be r
|
||||
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.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +29,6 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be r
|
||||
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.
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
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 (1 errors) ====
|
||||
@@ -10,7 +10,7 @@ tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS2332: 'this' cannot be r
|
||||
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.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be referenced in current location.
|
||||
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 TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
||||
|
||||
|
||||
==== 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 TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +22,7 @@ tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot 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.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
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 (1 errors) ====
|
||||
@@ -12,7 +12,7 @@ tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS2332: 'this' cannot be r
|
||||
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.
|
||||
}
|
||||
}
|
||||
|
||||
10
tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts
Normal file
10
tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
class Based { }
|
||||
class Derived extends Based {
|
||||
public x: number;
|
||||
constructor() {
|
||||
super();
|
||||
this;
|
||||
this.x = 10;
|
||||
var that = this;
|
||||
}
|
||||
}
|
||||
10
tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts
Normal file
10
tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
class Based { }
|
||||
class Derived extends Based {
|
||||
public x: number;
|
||||
constructor() {
|
||||
this.x = 100;
|
||||
super();
|
||||
this.x = 10;
|
||||
var that = this;
|
||||
}
|
||||
}
|
||||
15
tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts
Normal file
15
tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
19
tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts
Normal file
19
tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class Based { constructor(...arg) { } }
|
||||
class Derived extends Based {
|
||||
public x: number;
|
||||
constructor() {
|
||||
super(this.x);
|
||||
}
|
||||
}
|
||||
10
tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts
Normal file
10
tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
class Base {
|
||||
constructor(...arg) {
|
||||
}
|
||||
}
|
||||
class Super extends Base {
|
||||
constructor() {
|
||||
(() => this); // No Error
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class Base {
|
||||
constructor(func: ()=>Base) {
|
||||
}
|
||||
}
|
||||
class Super extends Base {
|
||||
constructor() {
|
||||
super((() => this)); // No error
|
||||
}
|
||||
}
|
||||
10
tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts
Normal file
10
tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
class Base {
|
||||
constructor(...arg) {
|
||||
}
|
||||
}
|
||||
class Super extends Base {
|
||||
constructor() {
|
||||
var that = this;
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class ClassWithNoInitializer extends BaseErrClass {
|
||||
t;
|
||||
//'this' in optional super call
|
||||
constructor() {
|
||||
super(this); // OK
|
||||
super(this); // Error
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user