Skip to content

Commit

Permalink
union of normal completions -> normal completion of union
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot committed Sep 17, 2024
1 parent 3b36e8b commit 3082e8c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/type-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ export function dominates(a: Type, b: Type): boolean {
return false;
}
function addToUnion(types: NonUnion[], type: NonUnion): Type {
if (type.kind === 'normal completion') {
const existingNormalCompletionIndex = types.findIndex(t => t.kind === 'normal completion');
if (existingNormalCompletionIndex !== -1) {
// prettier-ignore
const joined = join(types[existingNormalCompletionIndex], type) as Type & { kind: 'normal completion' };
if (types.length === 1) {
return joined;
}
const typesCopy = [...types];
typesCopy.splice(existingNormalCompletionIndex, 1, joined);
return { kind: 'union', of: typesCopy };
}
}

if (types.some(t => dominates(t, type))) {
return { kind: 'union', of: types };
}
Expand Down

0 comments on commit 3082e8c

Please sign in to comment.