Skip to content

fix: the function signatures of two interfaces are the same #1855 #2272

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

Closed
Closed
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
6 changes: 6 additions & 0 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2950,6 +2950,12 @@ export abstract class DeclaredElement extends Element {
case ElementKind.FUNCTION: {
return (<Function>self).signature.isAssignableTo((<Function>base).signature, /* sameSize */ true);
}
case ElementKind.FUNCTION_PROTOTYPE: {
let selfFunc = this.program.resolver.resolveFunction(<FunctionPrototype>self, null);
let baseFunc = this.program.resolver.resolveFunction(<FunctionPrototype>base, null);
if (!selfFunc || !baseFunc) return false;
return selfFunc.signature.isAssignableTo(baseFunc.signature, true, /* interface */ true);
}
case ElementKind.PROPERTY: {
let selfProperty = <Property>self;
let baseProperty = <Property>base;
Expand Down
20 changes: 11 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,15 +835,17 @@ export class Signature {
}

/** Tests if a value of this function type is assignable to a target of the specified function type. */
isAssignableTo(target: Signature, requireSameSize: bool = false): bool {

// check `this` type
var thisThisType = this.thisType;
var targetThisType = target.thisType;
if (thisThisType) {
if (!targetThisType || !thisThisType.isAssignableTo(targetThisType)) return false;
} else if (targetThisType) {
return false;
isAssignableTo(target: Signature, requireSameSize: bool = false, isInterface: bool = false): bool {

if (!isInterface) {
// check `this` type
var thisThisType = this.thisType;
var targetThisType = target.thisType;
if (thisThisType) {
if (!targetThisType || !thisThisType.isAssignableTo(targetThisType)) return false;
} else if (targetThisType) {
return false;
}
Comment on lines +840 to +848
Copy link
Member

@dcodeIO dcodeIO Apr 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One case I could imagine where skipping the check entirely leads to issues is an override of (this: i32, ...): ..., where then there would be two classes extending the same interface with an incompatible this type. Perhaps keep a check for managed-ness / strict assignability of the types?

}

// check rest parameter
Expand Down
Loading