Skip to content

Create a new pull request by comparing changes across two branches #847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31890,7 +31890,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
reportErrors: boolean,
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
): readonly Diagnostic[] | undefined {

const errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean } = { errors: undefined, skipLogging: true };
if (isJsxOpeningLikeElement(node)) {
if (!checkApplicableSignatureForJsxOpeningLikeElement(node, signature, relation, checkMode, reportErrors, containingMessageChain, errorOutputContainer)) {
Expand All @@ -31900,10 +31899,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return undefined;
}
const thisType = getThisTypeOfSignature(signature);
if (thisType && thisType !== voidType && node.kind !== SyntaxKind.NewExpression) {
if (thisType && thisType !== voidType && !(isNewExpression(node) || isCallExpression(node) && isSuperProperty(node.expression))) {
// If the called expression is not of the form `x.f` or `x["f"]`, then sourceType = voidType
// If the signature's 'this' type is voidType, then the check is skipped -- anything is compatible.
// If the expression is a new expression, then the check is skipped.
// If the expression is a new expression or super call expression, then the check is skipped.
const thisArgumentNode = getThisArgumentOfCall(node);
const thisArgumentType = getThisArgumentType(thisArgumentNode);
const errorNode = reportErrors ? (thisArgumentNode || node) : undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,10 @@ tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(178,22): e
const f4 = async <T>(this: {n: number}, m: number) => m + this.n;
~~~~~~~~~~~~~~~~~
!!! error TS2730: An arrow function cannot have a 'this' parameter.

class Derived3 extends Base2 {
f(this: this) {
super.polymorphic();
}
}

11 changes: 11 additions & 0 deletions tests/baselines/reference/thisTypeInFunctionsNegative.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ c.explicitProperty = (this, m) => m + this.n;
const f2 = <T>(this: {n: number}, m: number) => m + this.n;
const f3 = async (this: {n: number}, m: number) => m + this.n;
const f4 = async <T>(this: {n: number}, m: number) => m + this.n;

class Derived3 extends Base2 {
f(this: this) {
super.polymorphic();
}
}


//// [thisTypeInFunctionsNegative.js]
Expand Down Expand Up @@ -332,3 +338,8 @@ c.explicitProperty = (m) => m + this.n;
const f2 = (m) => m + this.n;
const f3 = (m) => __awaiter(this, void 0, void 0, function* () { return m + this.n; });
const f4 = (m) => __awaiter(this, void 0, void 0, function* () { return m + this.n; });
class Derived3 extends Base2 {
f() {
super.polymorphic();
}
}
15 changes: 15 additions & 0 deletions tests/baselines/reference/thisTypeInFunctionsNegative.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -696,3 +696,18 @@ const f4 = async <T>(this: {n: number}, m: number) => m + this.n;
>m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 177, 39))
>this : Symbol(globalThis)

class Derived3 extends Base2 {
>Derived3 : Symbol(Derived3, Decl(thisTypeInFunctionsNegative.ts, 177, 65))
>Base2 : Symbol(Base2, Decl(thisTypeInFunctionsNegative.ts, 128, 1))

f(this: this) {
>f : Symbol(Derived3.f, Decl(thisTypeInFunctionsNegative.ts, 179, 30))
>this : Symbol(this, Decl(thisTypeInFunctionsNegative.ts, 180, 6))

super.polymorphic();
>super.polymorphic : Symbol(Base2.polymorphic, Decl(thisTypeInFunctionsNegative.ts, 130, 13))
>super : Symbol(Base2, Decl(thisTypeInFunctionsNegative.ts, 128, 1))
>polymorphic : Symbol(Base2.polymorphic, Decl(thisTypeInFunctionsNegative.ts, 130, 13))
}
}

16 changes: 16 additions & 0 deletions tests/baselines/reference/thisTypeInFunctionsNegative.types
Original file line number Diff line number Diff line change
Expand Up @@ -804,3 +804,19 @@ const f4 = async <T>(this: {n: number}, m: number) => m + this.n;
>this : typeof globalThis
>n : any

class Derived3 extends Base2 {
>Derived3 : Derived3
>Base2 : Base2

f(this: this) {
>f : (this: this) => void
>this : this

super.polymorphic();
>super.polymorphic() : number
>super.polymorphic : (this: this) => number
>super : Base2
>polymorphic : (this: this) => number
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,9 @@ c.explicitProperty = (this, m) => m + this.n;
const f2 = <T>(this: {n: number}, m: number) => m + this.n;
const f3 = async (this: {n: number}, m: number) => m + this.n;
const f4 = async <T>(this: {n: number}, m: number) => m + this.n;

class Derived3 extends Base2 {
f(this: this) {
super.polymorphic();
}
}