Skip to content

Commit 4171ae3

Browse files
author
chen ruixiang
committed
add more conditions for inherit compatible
1 parent 5798aaa commit 4171ae3

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

Diff for: src/types.ts

+23-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import {
77
Class,
88
Program,
9-
DecoratorFlags
9+
DecoratorFlags,
10+
ElementKind
1011
} from "./program";
1112

1213
import {
@@ -475,6 +476,26 @@ export class Type {
475476
return false;
476477
}
477478

479+
/** Tests if a value of this class is compatible to the target class / interface in the multi extends / implements situation. */
480+
isInheritCompatibleTo(target: Type | null): bool {
481+
if (target) {
482+
if (this.isInternalReference && target.isInternalReference && this.isManaged && target.isManaged) {
483+
let thisClass = this.getClass();
484+
let targetClass = target.getClass();
485+
if (thisClass && targetClass) {
486+
// extends ThisClass implements TargetInterface
487+
// implements ThisInterface, TargetInterface
488+
if (thisClass.kind == ElementKind.CLASS || thisClass.kind == ElementKind.INTERFACE) {
489+
if (targetClass.kind == ElementKind.INTERFACE) {
490+
return true;
491+
}
492+
}
493+
}
494+
}
495+
}
496+
return false;
497+
}
498+
478499
/** Tests if a value of this type is assignable to the target type excl. implicit conversion. */
479500
isStrictlyAssignableTo(target: Type, signednessIsRelevant: bool = false): bool {
480501
if (this.isReference) return this.isAssignableTo(target);
@@ -941,7 +962,7 @@ export class Signature {
941962
} else {
942963
// check kind of `this` type
943964
if (thisThisType) {
944-
if (!targetThisType || thisThisType.kind != targetThisType.kind || thisThisType.isReference != targetThisType.isReference) {
965+
if (!thisThisType.isInheritCompatibleTo(targetThisType)) {
945966
return false;
946967
}
947968
} else if (targetThisType) {

0 commit comments

Comments
 (0)