import { PrimitiveType } from "./PrimitiveType"; import { Type } from "./Type"; export const UNKNOWN_CAPACITY = "unknown"; export type ChannelCapacity = typeof UNKNOWN_CAPACITY | number; export class ChannelType extends Type { constructor(readonly elementsType: PrimitiveType, readonly capacity: ChannelCapacity) { super(); } override get isChannelType(): boolean { return true; } override equals(otherType: Type): boolean { if (otherType instanceof ChannelType) { return this.elementsType.equals(otherType.elementsType) && this.capacity === otherType.capacity; } else { return false; } } override isAssignableTo(otherType: Type): boolean { if (otherType instanceof ChannelType) { // As for arrays, we ignore the capacities of the channels for assignments return this.elementsType.equals(otherType.elementsType); // && (this.capacity === otherType.capacity || otherType.capacity === UNKNOWN_CAPACITY); } else { return false; } } override toString(): string { const capacityString = (this.capacity === UNKNOWN_CAPACITY) ? "?" : `${this.capacity}`; return `${this.elementsType.toString()}chan${capacityString}`; } }