mergeType static method

ClassType? mergeType(
  1. ClassType? oriType,
  2. ClassType? newType
)

(int -> double) / bool -> string -> dynamic Class / List -> dynamic

Implementation

static ClassType? mergeType(ClassType? oriType, ClassType? newType) {
  if (oriType == null || oriType.isNull) {
    return newType;
  } else if (newType == null || newType.isNull) {
    return oriType;
  } else if (oriType == newType) {
    return oriType;
  }

  if (oriType == ClassType.tInt || oriType == ClassType.tDouble) {
    if (newType == ClassType.tInt || newType == ClassType.tDouble) {
      return ClassType.tDouble;
    } else if (newType == ClassType.tBool || newType == ClassType.tString) {
      return ClassType.tString;
    } else {
      return ClassType.tDynamic;
    }
  } else if (oriType == ClassType.tBool) {
    if (newType == ClassType.tInt ||
        newType == ClassType.tDouble ||
        newType == ClassType.tString) {
      return ClassType.tString;
    } else {
      return ClassType.tDynamic;
    }
  } else if (oriType == ClassType.tString) {
    if (newType == ClassType.tInt ||
        newType == ClassType.tDouble ||
        newType == ClassType.tBool) {
      return ClassType.tString;
    } else {
      return ClassType.tDynamic;
    }
  } else {
    return ClassType.tDynamic;
  }
}