File: checkSuperCallBeforeThisAccess.types

package info (click to toggle)
node-typescript 5.0.4%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 459,116 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (279 lines) | stat: -rw-r--r-- 4,804 bytes parent folder | download | duplicates (4)
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
=== tests/cases/compiler/checkSuperCallBeforeThisAccess.ts ===
class A {
>A : A

    x = 1;
>x : number
>1 : 1
}

class C1 extends A {
>C1 : C1
>A : A

    constructor(n: number) {
>n : number

        let a1 = this;  // Error
>a1 : this
>this : this

        let a2 = this.x;  // Error
>a2 : number
>this.x : number
>this : this
>x : number

        let a3 = super.x;  // Error
>a3 : number
>super.x : number
>super : A
>x : number

        let a4 = () => this;
>a4 : () => this
>() => this : () => this
>this : this

        let a5 = () => this.x;
>a5 : () => number
>() => this.x : () => number
>this.x : number
>this : this
>x : number

        let a6 = () => super.x;
>a6 : () => number
>() => super.x : () => number
>super.x : number
>super : A
>x : number

        if (!!true) {
>!!true : true
>!true : false
>true : true

            super();
>super() : void
>super : typeof A

            let b1 = this;
>b1 : this
>this : this

            let b2 = this.x;
>b2 : number
>this.x : number
>this : this
>x : number

            let b3 = super.x;
>b3 : number
>super.x : number
>super : A
>x : number
        }
        else {
            let c1 = this;  // Error
>c1 : this
>this : this

            let c2 = this.x;  // Error
>c2 : number
>this.x : number
>this : this
>x : number

            let c3 = super.x;  // Error
>c3 : number
>super.x : number
>super : A
>x : number
        }
        if (!!true) {
>!!true : true
>!true : false
>true : true

            switch (n) {
>n : number

                case 1:
>1 : 1

                    super();
>super() : void
>super : typeof A

                    let d1 = this.x;
>d1 : number
>this.x : number
>this : this
>x : number

                case 2:
>2 : 2

                    let d2 = this.x;  // Error
>d2 : number
>this.x : number
>this : this
>x : number

                default:
                    super();
>super() : void
>super : typeof A

                    let d3 = this.x;
>d3 : number
>this.x : number
>this : this
>x : number
            }
            let d4 = this.x;
>d4 : number
>this.x : number
>this : this
>x : number
        }
        if (!!true) {
>!!true : true
>!true : false
>true : true

            let e1 = { w: !!true ? super() : 0 };
>e1 : { w: number | void; }
>{ w: !!true ? super() : 0 } : { w: number | void; }
>w : number | void
>!!true ? super() : 0 : void | 0
>!!true : true
>!true : false
>true : true
>super() : void
>super : typeof A
>0 : 0

            let e2 = this.x;  // Error
>e2 : number
>this.x : number
>this : this
>x : number

            let e3 = { w: !!true ? super() : super() };
>e3 : { w: void; }
>{ w: !!true ? super() : super() } : { w: void; }
>w : void
>!!true ? super() : super() : void
>!!true : true
>!true : false
>true : true
>super() : void
>super : typeof A
>super() : void
>super : typeof A

            let e4 = this.x;
>e4 : number
>this.x : number
>this : this
>x : number
        }
        let f1 = this;  // Error
>f1 : this
>this : this

        let f2 = this.x;  // Error
>f2 : number
>this.x : number
>this : this
>x : number

        let f3 = super.x;  // Error
>f3 : number
>super.x : number
>super : A
>x : number
    }
}

// Repro from #38512

export class Foo {
>Foo : Foo

    constructor(value: number) {
>value : number
    }
}

export class BarCorrectlyFails extends Foo {
>BarCorrectlyFails : BarCorrectlyFails
>Foo : Foo

    constructor(something: boolean) {
>something : boolean

        if (!something) {
>!something : boolean
>something : boolean

            const value = this.bar();  // Error
>value : number
>this.bar() : number
>this.bar : () => number
>this : this
>bar : () => number

            super(value);
>super(value) : void
>super : typeof Foo
>value : number
        }
        else {
            super(1337);
>super(1337) : void
>super : typeof Foo
>1337 : 1337
        }
    }
    bar(): number { return 4; }
>bar : () => number
>4 : 4
}

export class BarIncorrectlyWorks extends Foo {
>BarIncorrectlyWorks : BarIncorrectlyWorks
>Foo : Foo

    constructor(something: boolean) {
>something : boolean

        if (something) {
>something : boolean

            super(1337);
>super(1337) : void
>super : typeof Foo
>1337 : 1337
        }
        else {
            const value = this.bar();  // Error
>value : number
>this.bar() : number
>this.bar : () => number
>this : this
>bar : () => number

            super(value);
>super(value) : void
>super : typeof Foo
>value : number
        }
    }
    bar(): number { return 4; }
>bar : () => number
>4 : 4
}