Skip to content

Fix: multi implements issue #2510

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 11 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
42 changes: 40 additions & 2 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3012,13 +3012,31 @@ export abstract class DeclaredElement extends Element {
case ElementKind.FUNCTION: {
return (<Function>self).signature.isAssignableTo((<Function>base).signature);
}
case ElementKind.FUNCTION_PROTOTYPE : {
let selfFunction = this.program.resolver.resolveFunction(<FunctionPrototype>self, null);
let baseFunction = this.program.resolver.resolveFunction(<FunctionPrototype>base, null);
if (selfFunction && baseFunction) {
return selfFunction.signature.isAssignableTo(baseFunction.signature, true);
} else {
return false;
}
}
case ElementKind.PROPERTY_PROTOTYPE: {
let selfProperty = this.program.resolver.resolveProperty(<PropertyPrototype>self);
if (!selfProperty) return false;
let baseProperty = this.program.resolver.resolveProperty(<PropertyPrototype>base);
if (!baseProperty) return false;
self = selfProperty;
base = baseProperty;
// fall-through
}
case ElementKind.PROPERTY: {
let selfProperty = <Property>self;
let baseProperty = <Property>base;
let selfGetter = selfProperty.getterInstance;
let baseGetter = baseProperty.getterInstance;
if (selfGetter) {
if (!baseGetter || !selfGetter.signature.isAssignableTo(baseGetter.signature)) {
if (!baseGetter || !selfGetter.signature.isAssignableTo(baseGetter.signature, true)) {
return false;
}
} else if (baseGetter) {
Expand All @@ -3027,7 +3045,7 @@ export abstract class DeclaredElement extends Element {
let selfSetter = selfProperty.setterInstance;
let baseSetter = baseProperty.setterInstance;
if (selfSetter) {
if (!baseSetter || !selfSetter.signature.isAssignableTo(baseSetter.signature)) {
if (!baseSetter || !selfSetter.signature.isAssignableTo(baseSetter.signature, true)) {
return false;
}
} else if (baseSetter) {
Expand All @@ -3037,6 +3055,26 @@ export abstract class DeclaredElement extends Element {
}
}
}
// TODO: field and property cannot override each other, have different codegen
// if (self.kind == ElementKind.FIELD && base.kind == ElementKind.PROPERTY_PROTOTYPE) {
// // class A implement I, class B extends A implement I
// let selfField = <Field>self;
// let baseProperty = this.program.resolver.resolveProperty(<PropertyPrototype>base);
// if (!selfField.internalGetterSignature || !selfField.internalSetterSignature || !baseProperty) {
// return false;
// }
// let baseGetterInsance = baseProperty.getterInstance;
// let baseSetterInsance = baseProperty.setterInstance;
// if (baseGetterInsance && baseSetterInsance) {
// if (!selfField.internalGetterSignature.isAssignableTo(baseGetterInsance.signature)
// || !selfField.internalSetterSignature.isAssignableTo(baseSetterInsance.signature)) {
// return false;
// }
// } else {
// return false;
// }
// return true;
// }
return false;
}
}
Expand Down
24 changes: 17 additions & 7 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,17 +926,27 @@ export class Signature {
}

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

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

// check rest parameter
Expand Down
Loading