Skip to content

Commit bccd2f4

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

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/type-logic.ts

+13
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ 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+
const joined = join(types[existingNormalCompletionIndex], type) as Type & { kind: 'normal completion' };
147+
if (types.length === 1) {
148+
return joined;
149+
}
150+
const typesCopy = [...types];
151+
typesCopy.splice(existingNormalCompletionIndex, 1, joined);
152+
return { kind: 'union', of: typesCopy };
153+
}
154+
}
155+
143156
if (types.some(t => dominates(t, type))) {
144157
return { kind: 'union', of: types };
145158
}

0 commit comments

Comments
 (0)