1
0

compoundType.js 823 B

123456789101112131415161718192021222324252627282930313233343536
  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. stringInfo () {
  18. const list = this.innerType.stringInfo();
  19. list.forEach(v => {
  20. v.dim = this.dimensions;
  21. });
  22. return list;
  23. }
  24. canAccept (another) {
  25. if(another instanceof CompoundType) {
  26. return this.dimensions > another.dimensions && this.innerType.isCompatible(another.innerType);
  27. } else {
  28. return this.innerType.isCompatible(another);
  29. }
  30. }
  31. }