Skip to content

Commit 9f5310f

Browse files
committed
Use the existing checkCrossProductUnion helper
1 parent 6650496 commit 9f5310f

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13394,6 +13394,7 @@ namespace ts {
1339413394
function checkCrossProductUnion(types: readonly Type[]) {
1339513395
const size = reduceLeft(types, (n, t) => n * (t.flags & TypeFlags.Union ? (<UnionType>t).types.length : t.flags & TypeFlags.Never ? 0 : 1), 1);
1339613396
if (size >= 100000) {
13397+
tracing.instant(tracing.Phase.Check, "checkCrossProductUnion_DepthLimit", { typeIds: types.map(t => t.id), size });
1339713398
error(currentNode, Diagnostics.Expression_produces_a_union_type_that_is_too_complex_to_represent);
1339813399
return false;
1339913400
}
@@ -14458,14 +14459,18 @@ namespace ts {
1445814459
if (merged) {
1445914460
return getSpreadType(merged, right, symbol, objectFlags, readonly);
1446014461
}
14461-
return errorTypeIfTooLarge() ?? mapType(left, t => getSpreadType(t, right, symbol, objectFlags, readonly));
14462+
return checkCrossProductUnion([left, right])
14463+
? mapType(left, t => getSpreadType(t, right, symbol, objectFlags, readonly))
14464+
: errorType;
1446214465
}
1446314466
if (right.flags & TypeFlags.Union) {
1446414467
const merged = tryMergeUnionOfObjectTypeAndEmptyObject(right as UnionType, readonly);
1446514468
if (merged) {
1446614469
return getSpreadType(left, merged, symbol, objectFlags, readonly);
1446714470
}
14468-
return errorTypeIfTooLarge() ?? mapType(right, t => getSpreadType(left, t, symbol, objectFlags, readonly));
14471+
return checkCrossProductUnion([left, right])
14472+
? mapType(right, t => getSpreadType(left, t, symbol, objectFlags, readonly))
14473+
: errorType;
1446914474
}
1447014475
if (right.flags & (TypeFlags.BooleanLike | TypeFlags.NumberLike | TypeFlags.BigIntLike | TypeFlags.StringLike | TypeFlags.EnumLike | TypeFlags.NonPrimitive | TypeFlags.Index)) {
1447114476
return left;
@@ -14544,17 +14549,6 @@ namespace ts {
1454414549
getIndexInfoWithReadonly(numberIndexInfo, readonly));
1454514550
spread.objectFlags |= ObjectFlags.ObjectLiteral | ObjectFlags.ContainsObjectOrArrayLiteral | ObjectFlags.ContainsSpread | objectFlags;
1454614551
return spread;
14547-
14548-
function errorTypeIfTooLarge(): Type | undefined {
14549-
if (left.flags & right.flags & TypeFlags.Union) {
14550-
const resultSize = (left as UnionType).types.length * (right as UnionType).types.length;
14551-
if (resultSize > 100000) {
14552-
tracing.instant(tracing.Phase.Check, "getSpreadType_DepthLimit", { leftId: left.id, rightId: right.id });
14553-
error(currentNode, Diagnostics.Spread_expression_produces_a_union_type_that_is_too_complex_to_represent);
14554-
return errorType;
14555-
}
14556-
}
14557-
}
1455814552
}
1455914553

1456014554
/** We approximate own properties as non-methods plus methods that are inside the object literal */

src/compiler/diagnosticMessages.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,10 +3048,6 @@
30483048
"category": "Error",
30493049
"code": 2795
30503050
},
3051-
"Spread expression produces a union type that is too complex to represent.": {
3052-
"category": "Error",
3053-
"code": 2796
3054-
},
30553051

30563052
"Import declaration '{0}' is using private name '{1}'.": {
30573053
"category": "Error",

tests/baselines/reference/objectSpreadRepeatedComplexity.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/types/spread/objectSpreadRepeatedComplexity.ts(3,12): error TS2796: Spread expression produces a union type that is too complex to represent.
1+
tests/cases/conformance/types/spread/objectSpreadRepeatedComplexity.ts(3,12): error TS2590: Expression produces a union type that is too complex to represent.
22

33

44
==== tests/cases/conformance/types/spread/objectSpreadRepeatedComplexity.ts (1 errors) ====
@@ -166,5 +166,5 @@ tests/cases/conformance/types/spread/objectSpreadRepeatedComplexity.ts(3,12): er
166166
~~~~~~~~~~~
167167
};
168168
~~~~~
169-
!!! error TS2796: Spread expression produces a union type that is too complex to represent.
169+
!!! error TS2590: Expression produces a union type that is too complex to represent.
170170
}

0 commit comments

Comments
 (0)