forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkSuperCallBeforeThisAccess.errors.txt
138 lines (130 loc) · 7.36 KB
/
checkSuperCallBeforeThisAccess.errors.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
checkSuperCallBeforeThisAccess.ts(7,18): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
checkSuperCallBeforeThisAccess.ts(8,18): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
checkSuperCallBeforeThisAccess.ts(9,18): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
checkSuperCallBeforeThisAccess.ts(9,24): error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
checkSuperCallBeforeThisAccess.ts(12,30): error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
checkSuperCallBeforeThisAccess.ts(17,28): error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
checkSuperCallBeforeThisAccess.ts(20,22): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
checkSuperCallBeforeThisAccess.ts(21,22): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
checkSuperCallBeforeThisAccess.ts(22,22): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
checkSuperCallBeforeThisAccess.ts(22,28): error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
checkSuperCallBeforeThisAccess.ts(30,30): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
checkSuperCallBeforeThisAccess.ts(39,22): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
checkSuperCallBeforeThisAccess.ts(43,18): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
checkSuperCallBeforeThisAccess.ts(44,18): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
checkSuperCallBeforeThisAccess.ts(45,18): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
checkSuperCallBeforeThisAccess.ts(45,24): error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
checkSuperCallBeforeThisAccess.ts(59,27): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
checkSuperCallBeforeThisAccess.ts(75,27): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
==== checkSuperCallBeforeThisAccess.ts (18 errors) ====
class A {
x = 1;
}
class C1 extends A {
constructor(n: number) {
let a1 = this; // Error
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
let a2 = this.x; // Error
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
let a3 = super.x; // Error
~~~~~
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
~
!!! error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
let a4 = () => this;
let a5 = () => this.x;
let a6 = () => super.x;
~
!!! error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
if (!!true) {
super();
let b1 = this;
let b2 = this.x;
let b3 = super.x;
~
!!! error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
}
else {
let c1 = this; // Error
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
let c2 = this.x; // Error
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
let c3 = super.x; // Error
~~~~~
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
~
!!! error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
}
if (!!true) {
switch (n) {
case 1:
super();
let d1 = this.x;
case 2:
let d2 = this.x; // Error
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
default:
super();
let d3 = this.x;
}
let d4 = this.x;
}
if (!!true) {
let e1 = { w: !!true ? super() : 0 };
let e2 = this.x; // Error
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
let e3 = { w: !!true ? super() : super() };
let e4 = this.x;
}
let f1 = this; // Error
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
let f2 = this.x; // Error
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
let f3 = super.x; // Error
~~~~~
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
~
!!! error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
}
}
// Repro from #38512
export class Foo {
constructor(value: number) {
}
}
export class BarCorrectlyFails extends Foo {
constructor(something: boolean) {
if (!something) {
const value = this.bar(); // Error
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
super(value);
}
else {
super(1337);
}
}
bar(): number { return 4; }
}
export class BarIncorrectlyWorks extends Foo {
constructor(something: boolean) {
if (something) {
super(1337);
}
else {
const value = this.bar(); // Error
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
super(value);
}
}
bar(): number { return 4; }
}