Skip to content

Commit 9d15f0b

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

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/types.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
import {
77
Class,
88
Program,
9-
DecoratorFlags
9+
DecoratorFlags,
10+
ElementKind
1011
} from "./program";
1112

1213
import {
1314
TypeRef,
1415
createType
1516
} from "./module";
17+
import { NodeKind } from "./ast";
1618

1719
/** Indicates the kind of a type. */
1820
export const enum TypeKind {
@@ -475,6 +477,26 @@ export class Type {
475477
return false;
476478
}
477479

480+
/** Tests if a value of this class is compatible to the target class / interface in the multi extends / implements situation. */
481+
isInheritCompatibleTo(target: Type | null) {
482+
if (target) {
483+
if (this.isInternalReference && target.isInternalReference && this.isManaged && target.isManaged) {
484+
let thisClass = this.getClass();
485+
let targetClass = target.getClass();
486+
if (thisClass && targetClass) {
487+
// extends ThisClass implements TargetInterface
488+
// implements ThisInterface, TargetInterface
489+
if (thisClass.kind == ElementKind.CLASS || thisClass.kind == ElementKind.INTERFACE) {
490+
if (targetClass.kind == ElementKind.INTERFACE) {
491+
return true;
492+
}
493+
}
494+
}
495+
}
496+
}
497+
return false;
498+
}
499+
478500
/** Tests if a value of this type is assignable to the target type excl. implicit conversion. */
479501
isStrictlyAssignableTo(target: Type, signednessIsRelevant: bool = false): bool {
480502
if (this.isReference) return this.isAssignableTo(target);
@@ -941,7 +963,7 @@ export class Signature {
941963
} else {
942964
// check kind of `this` type
943965
if (thisThisType) {
944-
if (!targetThisType || thisThisType.kind != targetThisType.kind || thisThisType.isReference != targetThisType.isReference) {
966+
if (!thisThisType.isInheritCompatibleTo(targetThisType)) {
945967
return false;
946968
}
947969
} else if (targetThisType) {

0 commit comments

Comments
 (0)