multiType.js 661 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { Type } from "./type";
  2. export class MultiType extends Type {
  3. constructor (types) {
  4. super(null);
  5. this.types = types;
  6. }
  7. get value () {
  8. return null;
  9. }
  10. get ord () {
  11. return null;
  12. }
  13. stringInfo () {
  14. let list = [];
  15. for (let i = 0; i < this.types.length; i++) {
  16. const t = this.types[i];
  17. list = list.concat(t.stringInfo());
  18. }
  19. return list;
  20. }
  21. isCompatible (another) {
  22. if(another instanceof Type) {
  23. for (let i = 0; i < this.types.length; i++) {
  24. const t = this.types[i];
  25. if (another.isCompatible(t)) {
  26. return true;
  27. }
  28. }
  29. }
  30. return false;
  31. }
  32. }