From f104b53c050725f72a19f4d631817a5feb1e3529 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 4 May 2023 16:56:20 -0700 Subject: [PATCH] Revert changes and instead fix isGenericObjectType to be more conservative --- src/compiler/checker.ts | 13 ++----------- src/compiler/types.ts | 19 +++++++++---------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 63f6fda4225f1..bf49a02fc963f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14078,7 +14078,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { else if (type !== firstType) { checkFlags |= CheckFlags.HasNonUniformType; } - if (isLiteralType(type) || isPatternLiteralType(type) || type === uniqueLiteralType) { + if (isLiteralType(type) || isPatternLiteralType(type)) { checkFlags |= CheckFlags.HasLiteralType; } if (type.flags & TypeFlags.Never && type !== uniqueLiteralType) { @@ -17685,7 +17685,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // eagerly using the constraint type of 'this' at the given location. if (isGenericIndexType(indexType) || (accessNode && accessNode.kind !== SyntaxKind.IndexedAccessType ? isGenericTupleType(objectType) && !indexTypeLessThan(indexType, objectType.target.fixedLength) : - isGenericObjectType(objectType) && !(isTupleType(objectType) && indexTypeLessThan(indexType, objectType.target.fixedLength)) || !(accessFlags & AccessFlags.ResolveReducibleTypes) && isGenericReducibleType(objectType))) { + isGenericObjectType(objectType) && !(isTupleType(objectType) && indexTypeLessThan(indexType, objectType.target.fixedLength)) || isGenericReducibleType(objectType))) { if (objectType.flags & TypeFlags.AnyOrUnknown) { return objectType; } @@ -24511,15 +24511,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } } - // The following is a targeted fix to allow higher-kinded types to be emulated using the technique in #53970. - // Specifically, when an indexed access type was deferred because it has a reducible object type, here we force - // resolution of the type and then infer to the result. - if (target.flags & TypeFlags.IndexedAccess && isGenericReducibleType((target as IndexedAccessType).objectType)) { - const instantiated = getIndexedAccessType((target as IndexedAccessType).objectType, (target as IndexedAccessType).indexType, AccessFlags.ResolveReducibleTypes); - if (instantiated && instantiated !== target) { - inferFromTypes(source, instantiated); - } - } } if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && ( (source as TypeReference).target === (target as TypeReference).target || isArrayType(source) && isArrayType(target)) && diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 122ed908792fa..c97bbaffa2834 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -6593,16 +6593,15 @@ export interface TypeParameter extends InstantiableType { export const enum AccessFlags { None = 0, IncludeUndefined = 1 << 0, - ResolveReducibleTypes = 1 << 1, - NoIndexSignatures = 1 << 2, - Writing = 1 << 3, - CacheSymbol = 1 << 4, - NoTupleBoundsCheck = 1 << 5, - ExpressionPosition = 1 << 6, - ReportDeprecated = 1 << 7, - SuppressNoImplicitAnyError = 1 << 8, - Contextual = 1 << 9, - Persistent = IncludeUndefined | ResolveReducibleTypes, + NoIndexSignatures = 1 << 1, + Writing = 1 << 2, + CacheSymbol = 1 << 3, + NoTupleBoundsCheck = 1 << 4, + ExpressionPosition = 1 << 5, + ReportDeprecated = 1 << 6, + SuppressNoImplicitAnyError = 1 << 7, + Contextual = 1 << 8, + Persistent = IncludeUndefined, } // Indexed access types (TypeFlags.IndexedAccess)