compoundType.js 728 B

1234567891011121314151617181920212223242526272829
  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. console.log("canAccept: another is compound");
  20. return this.dimensions >= another.dimensions && this.innerType.isCompatible(another.innerType);
  21. } else {
  22. return this.innerType.isCompatible(another);
  23. }
  24. }
  25. }