|
6 | 6 | import {
|
7 | 7 | Class,
|
8 | 8 | Program,
|
9 |
| - DecoratorFlags |
| 9 | + DecoratorFlags, |
| 10 | + ElementKind |
10 | 11 | } from "./program";
|
11 | 12 |
|
12 | 13 | import {
|
13 | 14 | TypeRef,
|
14 | 15 | createType
|
15 | 16 | } from "./module";
|
| 17 | +import { NodeKind } from "./ast"; |
16 | 18 |
|
17 | 19 | /** Indicates the kind of a type. */
|
18 | 20 | export const enum TypeKind {
|
@@ -475,6 +477,26 @@ export class Type {
|
475 | 477 | return false;
|
476 | 478 | }
|
477 | 479 |
|
| 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 | + |
478 | 500 | /** Tests if a value of this type is assignable to the target type excl. implicit conversion. */
|
479 | 501 | isStrictlyAssignableTo(target: Type, signednessIsRelevant: bool = false): bool {
|
480 | 502 | if (this.isReference) return this.isAssignableTo(target);
|
@@ -941,7 +963,7 @@ export class Signature {
|
941 | 963 | } else {
|
942 | 964 | // check kind of `this` type
|
943 | 965 | if (thisThisType) {
|
944 |
| - if (!targetThisType || thisThisType.kind != targetThisType.kind || thisThisType.isReference != targetThisType.isReference) { |
| 966 | + if (!thisThisType.isInheritCompatibleTo(targetThisType)) { |
945 | 967 | return false;
|
946 | 968 | }
|
947 | 969 | } else if (targetThisType) {
|
|
0 commit comments