compoundType.js 674 B

12345678910111213141516171819202122232425262728
  1. import { Type } from "./type";
  2. export class CompoundType extends Type {
  3. constructor (type, dimensions) {
  4. super(null);
  5. this.innerType = type;
  6. this.dimensions = dimensions;
  7. }
  8. isCompatible (another) {
  9. if(another instanceof CompoundType){
  10. if(this.dimensions !== another.dimensions) {
  11. return false;
  12. }
  13. return this.innerType.isCompatible(another.innerType);
  14. }
  15. return false;
  16. }
  17. canAccept (another) {
  18. if(another instanceof CompoundType) {
  19. return this.dimensions > another.dimensions && this.innerType.isCompatible(another.innerType);
  20. } else {
  21. return this.innerType.isCompatible(another);
  22. }
  23. }
  24. }