Skip to content

Commit

Permalink
Revert changes and instead fix isGenericObjectType to be more conserv…
Browse files Browse the repository at this point in the history
…ative
  • Loading branch information
ahejlsberg committed May 4, 2023
1 parent dd88229 commit f104b53
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
13 changes: 2 additions & 11 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)) &&
Expand Down
19 changes: 9 additions & 10 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f104b53

Please sign in to comment.