package org.hummingbirdlang.types.composite;

import org.hummingbirdlang.types.CompositeType;
import org.hummingbirdlang.types.Property;
import org.hummingbirdlang.types.PropertyNotFoundException;
import org.hummingbirdlang.types.Type;

/**
 * Disjoint union type (aka. sum type): it is composed of members A and B.
 * Eventually the union is discriminated into either A or B.
 */
public class SumType extends CompositeType {
  public final Type[] subTypes;

  public SumType(Type[] subTypes) {
    this.subTypes = subTypes;
  }

  @Override
  public Property getProperty(String name) throws PropertyNotFoundException {
    throw new PropertyNotFoundException("Not yet implemented");
  }

  @Override
  public String toString() {
    StringBuilder result = new StringBuilder();
    boolean bar = false;
    for (Type subType : this.subTypes) {
      if (bar) {
        result.append(" | ");
      } else {
        bar = true;
      }
      result.append(subType.toString());
    }
    return result.toString();
  }
}

@@ -678,24 +678,446 @@
 ted%22);%0A  %7D%0A%0A
+  /**%0A   * Other type must be equal to or smaller than this union for equality%0A   * to hold.%0A   */%0A  @Override%0A  public boolean equals(Type otherType) %7B%0A    // Equality check first.%0A    if (this == otherType) %7B%0A      return true;%0A    %7D%0A    // Then check if we contain the other type.%0A    for (Type subType : this.subTypes) %7B%0A      if (subType.equals(otherType)) %7B%0A        return true;%0A      %7D%0A    %7D%0A    return false;%0A  %7D%0A%0A
   @Override%0A

Add basic type equality checking to sum type