Skip to content

Commit e92e18b

Browse files
committed
fix(51198): skip to check this context of type assignable to super
1 parent 4c9afe8 commit e92e18b

File tree

6 files changed

+55
-2
lines changed

6 files changed

+55
-2
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30805,7 +30805,6 @@ namespace ts {
3080530805
reportErrors: boolean,
3080630806
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
3080730807
): readonly Diagnostic[] | undefined {
30808-
3080930808
const errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean } = { errors: undefined, skipLogging: true };
3081030809
if (isJsxOpeningLikeElement(node)) {
3081130810
if (!checkApplicableSignatureForJsxOpeningLikeElement(node, signature, relation, checkMode, reportErrors, containingMessageChain, errorOutputContainer)) {
@@ -30815,7 +30814,7 @@ namespace ts {
3081530814
return undefined;
3081630815
}
3081730816
const thisType = getThisTypeOfSignature(signature);
30818-
if (thisType && thisType !== voidType && node.kind !== SyntaxKind.NewExpression) {
30817+
if (thisType && thisType !== voidType && !(isNewExpression(node) || isCallExpression(node) && isSuperProperty(node.expression))) {
3081930818
// If the called expression is not of the form `x.f` or `x["f"]`, then sourceType = voidType
3082030819
// If the signature's 'this' type is voidType, then the check is skipped -- anything is compatible.
3082130820
// If the expression is a new expression, then the check is skipped.

tests/baselines/reference/thisTypeInFunctionsNegative.errors.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,4 +439,10 @@ tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(178,22): e
439439
const f4 = async <T>(this: {n: number}, m: number) => m + this.n;
440440
~~~~~~~~~~~~~~~~~
441441
!!! error TS2730: An arrow function cannot have a 'this' parameter.
442+
443+
class Derived3 extends Base2 {
444+
f(this: this) {
445+
super.polymorphic();
446+
}
447+
}
442448

tests/baselines/reference/thisTypeInFunctionsNegative.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ c.explicitProperty = (this, m) => m + this.n;
177177
const f2 = <T>(this: {n: number}, m: number) => m + this.n;
178178
const f3 = async (this: {n: number}, m: number) => m + this.n;
179179
const f4 = async <T>(this: {n: number}, m: number) => m + this.n;
180+
181+
class Derived3 extends Base2 {
182+
f(this: this) {
183+
super.polymorphic();
184+
}
185+
}
180186

181187

182188
//// [thisTypeInFunctionsNegative.js]
@@ -332,3 +338,8 @@ c.explicitProperty = (m) => m + this.n;
332338
const f2 = (m) => m + this.n;
333339
const f3 = (m) => __awaiter(this, void 0, void 0, function* () { return m + this.n; });
334340
const f4 = (m) => __awaiter(this, void 0, void 0, function* () { return m + this.n; });
341+
class Derived3 extends Base2 {
342+
f() {
343+
super.polymorphic();
344+
}
345+
}

tests/baselines/reference/thisTypeInFunctionsNegative.symbols

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,3 +696,18 @@ const f4 = async <T>(this: {n: number}, m: number) => m + this.n;
696696
>m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 177, 39))
697697
>this : Symbol(globalThis)
698698

699+
class Derived3 extends Base2 {
700+
>Derived3 : Symbol(Derived3, Decl(thisTypeInFunctionsNegative.ts, 177, 65))
701+
>Base2 : Symbol(Base2, Decl(thisTypeInFunctionsNegative.ts, 128, 1))
702+
703+
f(this: this) {
704+
>f : Symbol(Derived3.f, Decl(thisTypeInFunctionsNegative.ts, 179, 30))
705+
>this : Symbol(this, Decl(thisTypeInFunctionsNegative.ts, 180, 6))
706+
707+
super.polymorphic();
708+
>super.polymorphic : Symbol(Base2.polymorphic, Decl(thisTypeInFunctionsNegative.ts, 130, 13))
709+
>super : Symbol(Base2, Decl(thisTypeInFunctionsNegative.ts, 128, 1))
710+
>polymorphic : Symbol(Base2.polymorphic, Decl(thisTypeInFunctionsNegative.ts, 130, 13))
711+
}
712+
}
713+

tests/baselines/reference/thisTypeInFunctionsNegative.types

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,3 +804,19 @@ const f4 = async <T>(this: {n: number}, m: number) => m + this.n;
804804
>this : typeof globalThis
805805
>n : any
806806

807+
class Derived3 extends Base2 {
808+
>Derived3 : Derived3
809+
>Base2 : Base2
810+
811+
f(this: this) {
812+
>f : (this: this) => void
813+
>this : this
814+
815+
super.polymorphic();
816+
>super.polymorphic() : number
817+
>super.polymorphic : (this: this) => number
818+
>super : Base2
819+
>polymorphic : (this: this) => number
820+
}
821+
}
822+

tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,9 @@ c.explicitProperty = (this, m) => m + this.n;
178178
const f2 = <T>(this: {n: number}, m: number) => m + this.n;
179179
const f3 = async (this: {n: number}, m: number) => m + this.n;
180180
const f4 = async <T>(this: {n: number}, m: number) => m + this.n;
181+
182+
class Derived3 extends Base2 {
183+
f(this: this) {
184+
super.polymorphic();
185+
}
186+
}

0 commit comments

Comments
 (0)