Skip to content

Commit 3082e8c

Browse files
committed
union of normal completions -> normal completion of union
1 parent 3b36e8b commit 3082e8c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/type-logic.ts

+14
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,20 @@ export function dominates(a: Type, b: Type): boolean {
140140
return false;
141141
}
142142
function addToUnion(types: NonUnion[], type: NonUnion): Type {
143+
if (type.kind === 'normal completion') {
144+
const existingNormalCompletionIndex = types.findIndex(t => t.kind === 'normal completion');
145+
if (existingNormalCompletionIndex !== -1) {
146+
// prettier-ignore
147+
const joined = join(types[existingNormalCompletionIndex], type) as Type & { kind: 'normal completion' };
148+
if (types.length === 1) {
149+
return joined;
150+
}
151+
const typesCopy = [...types];
152+
typesCopy.splice(existingNormalCompletionIndex, 1, joined);
153+
return { kind: 'union', of: typesCopy };
154+
}
155+
}
156+
143157
if (types.some(t => dominates(t, type))) {
144158
return { kind: 'union', of: types };
145159
}

0 commit comments

Comments
 (0)