Skip to content

Commit 5400152

Browse files
committed
Revert "Fix crash when serializing the return type of a generic call to Array.prototype.flat (microsoft#38904) (microsoft#39079)"
This reverts commit 986e9dd.
1 parent c6f9343 commit 5400152

File tree

47 files changed

+222
-503
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+222
-503
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4397,8 +4397,8 @@ namespace ts {
43974397
context.inferTypeParameters = (<ConditionalType>type).root.inferTypeParameters;
43984398
const extendsTypeNode = typeToTypeNodeHelper((<ConditionalType>type).extendsType, context);
43994399
context.inferTypeParameters = saveInferTypeParameters;
4400-
const trueTypeNode = typeToTypeNodeOrCircularityElision(getTrueTypeFromConditionalType(<ConditionalType>type));
4401-
const falseTypeNode = typeToTypeNodeOrCircularityElision(getFalseTypeFromConditionalType(<ConditionalType>type));
4400+
const trueTypeNode = typeToTypeNodeHelper(getTrueTypeFromConditionalType(<ConditionalType>type), context);
4401+
const falseTypeNode = typeToTypeNodeHelper(getFalseTypeFromConditionalType(<ConditionalType>type), context);
44024402
context.approximateLength += 15;
44034403
return createConditionalTypeNode(checkTypeNode, extendsTypeNode, trueTypeNode, falseTypeNode);
44044404
}
@@ -4408,21 +4408,6 @@ namespace ts {
44084408

44094409
return Debug.fail("Should be unreachable.");
44104410

4411-
4412-
function typeToTypeNodeOrCircularityElision(type: Type) {
4413-
if (type.flags & TypeFlags.Union) {
4414-
if (context.visitedTypes && context.visitedTypes.has("" + getTypeId(type))) {
4415-
if (!(context.flags & NodeBuilderFlags.AllowAnonymousIdentifier)) {
4416-
context.encounteredError = true;
4417-
context.tracker?.reportCyclicStructureError?.();
4418-
}
4419-
return createElidedInformationPlaceholder(context);
4420-
}
4421-
return visitAndTransformType(type, type => typeToTypeNodeHelper(type, context));
4422-
}
4423-
return typeToTypeNodeHelper(type, context);
4424-
}
4425-
44264411
function createMappedTypeNodeFromType(type: MappedType) {
44274412
Debug.assert(!!(type.flags & TypeFlags.Object));
44284413
const readonlyToken = type.declaration.readonlyToken ? <ReadonlyToken | PlusToken | MinusToken>createToken(type.declaration.readonlyToken.kind) : undefined;
@@ -12809,12 +12794,10 @@ namespace ts {
1280912794
return links.resolvedType;
1281012795
}
1281112796

12812-
function createIndexedAccessType(objectType: Type, indexType: Type, aliasSymbol: Symbol | undefined, aliasTypeArguments: readonly Type[] | undefined) {
12797+
function createIndexedAccessType(objectType: Type, indexType: Type) {
1281312798
const type = <IndexedAccessType>createType(TypeFlags.IndexedAccess);
1281412799
type.objectType = objectType;
1281512800
type.indexType = indexType;
12816-
type.aliasSymbol = aliasSymbol;
12817-
type.aliasTypeArguments = aliasTypeArguments;
1281812801
return type;
1281912802
}
1282012803

@@ -13146,11 +13129,11 @@ namespace ts {
1314613129
return instantiateType(getTemplateTypeFromMappedType(objectType), templateMapper);
1314713130
}
1314813131

13149-
function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression, aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[]): Type {
13150-
return getIndexedAccessTypeOrUndefined(objectType, indexType, accessNode, AccessFlags.None, aliasSymbol, aliasTypeArguments) || (accessNode ? errorType : unknownType);
13132+
function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression): Type {
13133+
return getIndexedAccessTypeOrUndefined(objectType, indexType, accessNode, AccessFlags.None) || (accessNode ? errorType : unknownType);
1315113134
}
1315213135

13153-
function getIndexedAccessTypeOrUndefined(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression, accessFlags = AccessFlags.None, aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[]): Type | undefined {
13136+
function getIndexedAccessTypeOrUndefined(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression, accessFlags = AccessFlags.None): Type | undefined {
1315413137
if (objectType === wildcardType || indexType === wildcardType) {
1315513138
return wildcardType;
1315613139
}
@@ -13172,7 +13155,7 @@ namespace ts {
1317213155
const id = objectType.id + "," + indexType.id;
1317313156
let type = indexedAccessTypes.get(id);
1317413157
if (!type) {
13175-
indexedAccessTypes.set(id, type = createIndexedAccessType(objectType, indexType, aliasSymbol, aliasTypeArguments));
13158+
indexedAccessTypes.set(id, type = createIndexedAccessType(objectType, indexType));
1317613159
}
1317713160
return type;
1317813161
}
@@ -13200,7 +13183,7 @@ namespace ts {
1320013183
if (wasMissingProp) {
1320113184
return undefined;
1320213185
}
13203-
return accessFlags & AccessFlags.Writing ? getIntersectionType(propTypes, aliasSymbol, aliasTypeArguments) : getUnionType(propTypes, UnionReduction.Literal, aliasSymbol, aliasTypeArguments);
13186+
return accessFlags & AccessFlags.Writing ? getIntersectionType(propTypes) : getUnionType(propTypes);
1320413187
}
1320513188
return getPropertyTypeForIndexType(objectType, apparentObjectType, indexType, indexType, /* supressNoImplicitAnyError */ false, accessNode, accessFlags | AccessFlags.CacheSymbol);
1320613189
}
@@ -13210,8 +13193,7 @@ namespace ts {
1321013193
if (!links.resolvedType) {
1321113194
const objectType = getTypeFromTypeNode(node.objectType);
1321213195
const indexType = getTypeFromTypeNode(node.indexType);
13213-
const potentialAlias = getAliasSymbolForTypeNode(node);
13214-
const resolved = getIndexedAccessType(objectType, indexType, node, potentialAlias, getTypeArgumentsForAliasSymbol(potentialAlias));
13196+
const resolved = getIndexedAccessType(objectType, indexType, node);
1321513197
links.resolvedType = resolved.flags & TypeFlags.IndexedAccess &&
1321613198
(<IndexedAccessType>resolved).objectType === objectType &&
1321713199
(<IndexedAccessType>resolved).indexType === indexType ?
@@ -14359,7 +14341,7 @@ namespace ts {
1435914341
return getIndexType(instantiateType((<IndexType>type).type, mapper));
1436014342
}
1436114343
if (flags & TypeFlags.IndexedAccess) {
14362-
return getIndexedAccessType(instantiateType((<IndexedAccessType>type).objectType, mapper), instantiateType((<IndexedAccessType>type).indexType, mapper), /*accessNode*/ undefined, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper));
14344+
return getIndexedAccessType(instantiateType((<IndexedAccessType>type).objectType, mapper), instantiateType((<IndexedAccessType>type).indexType, mapper));
1436314345
}
1436414346
if (flags & TypeFlags.Conditional) {
1436514347
return getConditionalTypeInstantiation(<ConditionalType>type, combineTypeMappers((<ConditionalType>type).mapper, mapper));

src/compiler/diagnosticMessages.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,10 +3509,6 @@
35093509
"category": "Error",
35103510
"code": 5083
35113511
},
3512-
"The inferred type of '{0}' references a type with a cyclic structure which cannot be trivially serialized. A type annotation is necessary.": {
3513-
"category": "Error",
3514-
"code": 5088
3515-
},
35163512

35173513
"Generates a sourcemap for each corresponding '.d.ts' file.": {
35183514
"category": "Message",

src/compiler/transformers/declarations.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ namespace ts {
7272
trackSymbol,
7373
reportInaccessibleThisError,
7474
reportInaccessibleUniqueSymbolError,
75-
reportCyclicStructureError,
7675
reportPrivateInBaseOfClassExpression,
7776
reportLikelyUnsafeImportRequiredError,
7877
moduleResolverHost: host,
@@ -176,13 +175,6 @@ namespace ts {
176175
}
177176
}
178177

179-
function reportCyclicStructureError() {
180-
if (errorNameNode) {
181-
context.addDiagnostic(createDiagnosticForNode(errorNameNode, Diagnostics.The_inferred_type_of_0_references_a_type_with_a_cyclic_structure_which_cannot_be_trivially_serialized_A_type_annotation_is_necessary,
182-
declarationNameToString(errorNameNode)));
183-
}
184-
}
185-
186178
function reportInaccessibleThisError() {
187179
if (errorNameNode) {
188180
context.addDiagnostic(createDiagnosticForNode(errorNameNode, Diagnostics.The_inferred_type_of_0_references_an_inaccessible_1_type_A_type_annotation_is_necessary,

src/compiler/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6479,7 +6479,6 @@ namespace ts {
64796479
reportInaccessibleThisError?(): void;
64806480
reportPrivateInBaseOfClassExpression?(propertyName: string): void;
64816481
reportInaccessibleUniqueSymbolError?(): void;
6482-
reportCyclicStructureError?(): void;
64836482
reportLikelyUnsafeImportRequiredError?(specifier: string): void;
64846483
moduleResolverHost?: ModuleSpecifierResolutionHost & { getCommonSourceDirectory(): string };
64856484
trackReferencedAmbientModule?(decl: ModuleDeclaration, symbol: Symbol): void;

tests/baselines/reference/arrayFakeFlatNoCrashInferenceDeclarations.errors.txt

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/baselines/reference/arrayFakeFlatNoCrashInferenceDeclarations.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/baselines/reference/arrayFakeFlatNoCrashInferenceDeclarations.symbols

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)