Skip to content

Commit 955e673

Browse files
Merge pull request #340 from microsoft/main
Create a new pull request by comparing changes across two branches
2 parents 20279d7 + 4378441 commit 955e673

File tree

6 files changed

+56
-3
lines changed

6 files changed

+56
-3
lines changed

src/compiler/checker.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -31890,7 +31890,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3189031890
reportErrors: boolean,
3189131891
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
3189231892
): readonly Diagnostic[] | undefined {
31893-
3189431893
const errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean } = { errors: undefined, skipLogging: true };
3189531894
if (isJsxOpeningLikeElement(node)) {
3189631895
if (!checkApplicableSignatureForJsxOpeningLikeElement(node, signature, relation, checkMode, reportErrors, containingMessageChain, errorOutputContainer)) {
@@ -31900,10 +31899,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3190031899
return undefined;
3190131900
}
3190231901
const thisType = getThisTypeOfSignature(signature);
31903-
if (thisType && thisType !== voidType && node.kind !== SyntaxKind.NewExpression) {
31902+
if (thisType && thisType !== voidType && !(isNewExpression(node) || isCallExpression(node) && isSuperProperty(node.expression))) {
3190431903
// If the called expression is not of the form `x.f` or `x["f"]`, then sourceType = voidType
3190531904
// If the signature's 'this' type is voidType, then the check is skipped -- anything is compatible.
31906-
// If the expression is a new expression, then the check is skipped.
31905+
// If the expression is a new expression or super call expression, then the check is skipped.
3190731906
const thisArgumentNode = getThisArgumentOfCall(node);
3190831907
const thisArgumentType = getThisArgumentType(thisArgumentNode);
3190931908
const errorNode = reportErrors ? (thisArgumentNode || node) : undefined;

tests/baselines/reference/thisTypeInFunctionsNegative.errors.txt

+6
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

+11
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

+15
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

+16
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

+6
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)