Skip to content

Commit a323fdf

Browse files
committed
Instantiate this-type in super property access
1 parent e67df33 commit a323fdf

6 files changed

Lines changed: 371 additions & 78 deletions

File tree

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8569,7 +8569,7 @@ namespace ts {
85698569

85708570
return nodeCheckFlag === NodeCheckFlags.SuperStatic
85718571
? getBaseConstructorTypeOfClass(classType)
8572-
: baseClassType;
8572+
: getTypeWithThisArgument(baseClassType, classType.thisType);
85738573

85748574
function isLegalUsageOfSuperExpression(container: Node): boolean {
85758575
if (!container) {

tests/baselines/reference/superPropertyAccessNoError.errors.txt

Lines changed: 0 additions & 75 deletions
This file was deleted.

tests/baselines/reference/superPropertyAccessNoError.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class SomeBaseClass {
1616
return 3;
1717
}
1818

19+
returnThis() {
20+
return this;
21+
}
1922
}
2023

2124
class SomeDerivedClass extends SomeBaseClass {
@@ -58,7 +61,14 @@ class SomeDerivedClass extends SomeBaseClass {
5861
var x: number;
5962
}
6063

61-
}
64+
returnThis() {
65+
return super.returnThis();
66+
}
67+
}
68+
69+
let instance = new SomeDerivedClass();
70+
instance.returnThis().fn();
71+
6272

6373
//// [superPropertyAccessNoError.js]
6474
//super.publicInstanceMemberFunction in constructor of derived class
@@ -81,6 +91,9 @@ var SomeBaseClass = (function () {
8191
SomeBaseClass.func = function () {
8292
return 3;
8393
};
94+
SomeBaseClass.prototype.returnThis = function () {
95+
return this;
96+
};
8497
return SomeBaseClass;
8598
}());
8699
var SomeDerivedClass = (function (_super) {
@@ -126,5 +139,10 @@ var SomeDerivedClass = (function (_super) {
126139
enumerable: true,
127140
configurable: true
128141
});
142+
SomeDerivedClass.prototype.returnThis = function () {
143+
return _super.prototype.returnThis.call(this);
144+
};
129145
return SomeDerivedClass;
130146
}(SomeBaseClass));
147+
var instance = new SomeDerivedClass();
148+
instance.returnThis().fn();
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
=== tests/cases/conformance/expressions/superPropertyAccess/superPropertyAccessNoError.ts ===
2+
//super.publicInstanceMemberFunction in constructor of derived class
3+
//super.publicInstanceMemberFunction in instance member function of derived class
4+
//super.publicInstanceMemberFunction in instance member accessor(get and set) of derived class
5+
//super.publicInstanceMemberFunction in lambda in member function
6+
//super.publicStaticMemberFunction in static member function of derived class
7+
//super.publicStaticMemberFunction in static member accessor(get and set) of derived class
8+
9+
10+
class SomeBaseClass {
11+
>SomeBaseClass : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
12+
13+
public func() {
14+
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
15+
16+
return '';
17+
}
18+
19+
static func() {
20+
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 11, 5))
21+
22+
return 3;
23+
}
24+
25+
returnThis() {
26+
>returnThis : Symbol(SomeBaseClass.returnThis, Decl(superPropertyAccessNoError.ts, 15, 5))
27+
28+
return this;
29+
>this : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
30+
}
31+
}
32+
33+
class SomeDerivedClass extends SomeBaseClass {
34+
>SomeDerivedClass : Symbol(SomeDerivedClass, Decl(superPropertyAccessNoError.ts, 20, 1))
35+
>SomeBaseClass : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
36+
37+
constructor() {
38+
super();
39+
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
40+
41+
var x = super.func();
42+
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 25, 11), Decl(superPropertyAccessNoError.ts, 26, 11))
43+
>super.func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
44+
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
45+
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
46+
47+
var x: string;
48+
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 25, 11), Decl(superPropertyAccessNoError.ts, 26, 11))
49+
}
50+
51+
fn() {
52+
>fn : Symbol(SomeDerivedClass.fn, Decl(superPropertyAccessNoError.ts, 27, 5))
53+
54+
var x = super.func();
55+
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 30, 11), Decl(superPropertyAccessNoError.ts, 31, 11))
56+
>super.func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
57+
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
58+
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
59+
60+
var x: string;
61+
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 30, 11), Decl(superPropertyAccessNoError.ts, 31, 11))
62+
63+
var y = () => super.func();
64+
>y : Symbol(y, Decl(superPropertyAccessNoError.ts, 32, 11))
65+
>super.func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
66+
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
67+
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
68+
}
69+
70+
get a() {
71+
>a : Symbol(SomeDerivedClass.a, Decl(superPropertyAccessNoError.ts, 33, 5), Decl(superPropertyAccessNoError.ts, 39, 5))
72+
73+
var x = super.func();
74+
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 36, 11), Decl(superPropertyAccessNoError.ts, 37, 11))
75+
>super.func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
76+
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
77+
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
78+
79+
var x: string;
80+
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 36, 11), Decl(superPropertyAccessNoError.ts, 37, 11))
81+
82+
return null;
83+
}
84+
85+
set a(n) {
86+
>a : Symbol(SomeDerivedClass.a, Decl(superPropertyAccessNoError.ts, 33, 5), Decl(superPropertyAccessNoError.ts, 39, 5))
87+
>n : Symbol(n, Decl(superPropertyAccessNoError.ts, 41, 10))
88+
89+
var x = super.func();
90+
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 42, 11), Decl(superPropertyAccessNoError.ts, 43, 11))
91+
>super.func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
92+
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
93+
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
94+
95+
var x: string;
96+
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 42, 11), Decl(superPropertyAccessNoError.ts, 43, 11))
97+
}
98+
99+
static fn() {
100+
>fn : Symbol(SomeDerivedClass.fn, Decl(superPropertyAccessNoError.ts, 44, 5))
101+
102+
var x = super.func();
103+
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 47, 11), Decl(superPropertyAccessNoError.ts, 48, 11))
104+
>super.func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 11, 5))
105+
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
106+
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 11, 5))
107+
108+
var x: number;
109+
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 47, 11), Decl(superPropertyAccessNoError.ts, 48, 11))
110+
}
111+
112+
static get a() {
113+
>a : Symbol(SomeDerivedClass.a, Decl(superPropertyAccessNoError.ts, 49, 5), Decl(superPropertyAccessNoError.ts, 55, 5))
114+
115+
var x = super.func();
116+
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 52, 11), Decl(superPropertyAccessNoError.ts, 53, 11))
117+
>super.func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 11, 5))
118+
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
119+
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 11, 5))
120+
121+
var x: number;
122+
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 52, 11), Decl(superPropertyAccessNoError.ts, 53, 11))
123+
124+
return null;
125+
}
126+
127+
static set a(n) {
128+
>a : Symbol(SomeDerivedClass.a, Decl(superPropertyAccessNoError.ts, 49, 5), Decl(superPropertyAccessNoError.ts, 55, 5))
129+
>n : Symbol(n, Decl(superPropertyAccessNoError.ts, 57, 17))
130+
131+
var x = super.func();
132+
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 58, 11), Decl(superPropertyAccessNoError.ts, 59, 11))
133+
>super.func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 11, 5))
134+
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
135+
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 11, 5))
136+
137+
var x: number;
138+
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 58, 11), Decl(superPropertyAccessNoError.ts, 59, 11))
139+
}
140+
141+
returnThis() {
142+
>returnThis : Symbol(SomeDerivedClass.returnThis, Decl(superPropertyAccessNoError.ts, 60, 5))
143+
144+
return super.returnThis();
145+
>super.returnThis : Symbol(SomeBaseClass.returnThis, Decl(superPropertyAccessNoError.ts, 15, 5))
146+
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
147+
>returnThis : Symbol(SomeBaseClass.returnThis, Decl(superPropertyAccessNoError.ts, 15, 5))
148+
}
149+
}
150+
151+
let instance = new SomeDerivedClass();
152+
>instance : Symbol(instance, Decl(superPropertyAccessNoError.ts, 67, 3))
153+
>SomeDerivedClass : Symbol(SomeDerivedClass, Decl(superPropertyAccessNoError.ts, 20, 1))
154+
155+
instance.returnThis().fn();
156+
>instance.returnThis().fn : Symbol(SomeDerivedClass.fn, Decl(superPropertyAccessNoError.ts, 27, 5))
157+
>instance.returnThis : Symbol(SomeDerivedClass.returnThis, Decl(superPropertyAccessNoError.ts, 60, 5))
158+
>instance : Symbol(instance, Decl(superPropertyAccessNoError.ts, 67, 3))
159+
>returnThis : Symbol(SomeDerivedClass.returnThis, Decl(superPropertyAccessNoError.ts, 60, 5))
160+
>fn : Symbol(SomeDerivedClass.fn, Decl(superPropertyAccessNoError.ts, 27, 5))
161+

0 commit comments

Comments
 (0)