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 bccd2f4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/type-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@ 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) {
const joined = join(types[existingNormalCompletionIndex], type) as Type & { kind: 'normal completion' };

Check failure on line 146 in src/type-logic.ts

View workflow job for this annotation

GitHub Actions / Check

Replace `·kind:·'normal·completion'` with `⏎········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 bccd2f4

Please sign in to comment.