(typesToUnify: TypeRef[], typeName: string, isInferred: boolean)
| 202 | } |
| 203 | |
| 204 | function unifyTypes(typesToUnify: TypeRef[], typeName: string, isInferred: boolean): TypeRef { |
| 205 | if (typesToUnify.length === 0) { |
| 206 | return panic("Cannot unify empty list of types"); |
| 207 | } else if (typesToUnify.length === 1) { |
| 208 | return typesToUnify[0]; |
| 209 | } else { |
| 210 | const unionBuilder = new UnifyUnionBuilder(typeBuilder, typeName, isInferred, unifyTypes); |
| 211 | |
| 212 | const registerType = (t: Type): void => { |
| 213 | matchTypeExhaustive<void>( |
| 214 | t, |
| 215 | _anyType => unionBuilder.addAny(), |
| 216 | _nullType => unionBuilder.addNull(), |
| 217 | _boolType => unionBuilder.addBool(), |
| 218 | _integerType => unionBuilder.addInteger(), |
| 219 | _doubleType => unionBuilder.addDouble(), |
| 220 | _stringType => unionBuilder.addStringType("string"), |
| 221 | arrayType => unionBuilder.addArray(arrayType.items.typeRef), |
| 222 | classType => unionBuilder.addClass(classType.typeRef), |
| 223 | mapType => unionBuilder.addMap(mapType.values.typeRef), |
| 224 | enumType => enumType.cases.forEach(s => unionBuilder.addEnumCase(s)), |
| 225 | unionType => unionType.members.forEach(registerType), |
| 226 | _dateType => unionBuilder.addStringType("date"), |
| 227 | _timeType => unionBuilder.addStringType("time"), |
| 228 | _dateTimeType => unionBuilder.addStringType("date-time") |
| 229 | ); |
| 230 | }; |
| 231 | |
| 232 | for (const t of typesToUnify) { |
| 233 | registerType(getHopefullyFinishedType(typeBuilder, t)); |
| 234 | } |
| 235 | |
| 236 | return unionBuilder.buildUnion(false); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | function lookupRef(local: StringMap, localPath: Ref, ref: Ref): [StringMap, Ref] { |
| 241 | const first = ref.first(); |
no test coverage detected
searching dependent graphs…