Skip to content

Commit 71a7c19

Browse files
committed
Fix naming and update comment
1 parent 06f63b2 commit 71a7c19

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace ts {
114114

115115
let anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
116116
// The anyFunctionType contains the anyFunctionType by definition. The flag is further propagated
117-
// in getContainsLiteralFlagsOfTypes, and it is checked in inferFromTypes.
117+
// in getPropagatingFlagsOfTypes, and it is checked in inferFromTypes.
118118
anyFunctionType.flags |= TypeFlags.ContainsAnyFunctionType;
119119

120120
let noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
@@ -3761,22 +3761,23 @@ namespace ts {
37613761
}
37623762
}
37633763

3764-
// This function is used to propagate widening flags when creating new object types references and union types.
3765-
// It is only necessary to do so if a constituent type might be the undefined type, the null type, or the type
3766-
// of an object literal (since those types have widening related information we need to track).
3767-
function getContainsLiteralFlagsOfTypes(types: Type[]): TypeFlags {
3764+
// This function is used to propagate certain flags when creating new object type references and union types.
3765+
// It is only necessary to do so if a constituent type might be the undefined type, the null type, the type
3766+
// of an object literal or the anyFunctionType. This is because there are operations in the type checker
3767+
// that care about the presence of such types at arbitrary depth in a containing type.
3768+
function getPropagatingFlagsOfTypes(types: Type[]): TypeFlags {
37683769
let result: TypeFlags = 0;
37693770
for (let type of types) {
37703771
result |= type.flags;
37713772
}
3772-
return result & TypeFlags.ContainsLiteralFlags;
3773+
return result & TypeFlags.PropagatingFlags;
37733774
}
37743775

37753776
function createTypeReference(target: GenericType, typeArguments: Type[]): TypeReference {
37763777
let id = getTypeListId(typeArguments);
37773778
let type = target.instantiations[id];
37783779
if (!type) {
3779-
let flags = TypeFlags.Reference | getContainsLiteralFlagsOfTypes(typeArguments);
3780+
let flags = TypeFlags.Reference | getPropagatingFlagsOfTypes(typeArguments);
37803781
type = target.instantiations[id] = <TypeReference>createObjectType(flags, target.symbol);
37813782
type.target = target;
37823783
type.typeArguments = typeArguments;
@@ -4030,7 +4031,7 @@ namespace ts {
40304031
let id = getTypeListId(elementTypes);
40314032
let type = tupleTypes[id];
40324033
if (!type) {
4033-
type = tupleTypes[id] = <TupleType>createObjectType(TypeFlags.Tuple | getContainsLiteralFlagsOfTypes(elementTypes));
4034+
type = tupleTypes[id] = <TupleType>createObjectType(TypeFlags.Tuple | getPropagatingFlagsOfTypes(elementTypes));
40344035
type.elementTypes = elementTypes;
40354036
}
40364037
return type;
@@ -4179,7 +4180,7 @@ namespace ts {
41794180
let id = getTypeListId(typeSet);
41804181
let type = unionTypes[id];
41814182
if (!type) {
4182-
type = unionTypes[id] = <UnionType>createObjectType(TypeFlags.Union | getContainsLiteralFlagsOfTypes(typeSet));
4183+
type = unionTypes[id] = <UnionType>createObjectType(TypeFlags.Union | getPropagatingFlagsOfTypes(typeSet));
41834184
type.types = typeSet;
41844185
}
41854186
return type;
@@ -4213,7 +4214,7 @@ namespace ts {
42134214
let id = getTypeListId(typeSet);
42144215
let type = intersectionTypes[id];
42154216
if (!type) {
4216-
type = intersectionTypes[id] = <IntersectionType>createObjectType(TypeFlags.Intersection | getContainsLiteralFlagsOfTypes(typeSet));
4217+
type = intersectionTypes[id] = <IntersectionType>createObjectType(TypeFlags.Intersection | getPropagatingFlagsOfTypes(typeSet));
42174218
type.types = typeSet;
42184219
}
42194220
return type;
@@ -7103,7 +7104,7 @@ namespace ts {
71037104
let stringIndexType = getIndexType(IndexKind.String);
71047105
let numberIndexType = getIndexType(IndexKind.Number);
71057106
let result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType);
7106-
result.flags |= TypeFlags.ObjectLiteral | TypeFlags.FreshObjectLiteral | TypeFlags.ContainsObjectLiteral | (typeFlags & TypeFlags.ContainsLiteralFlags);
7107+
result.flags |= TypeFlags.ObjectLiteral | TypeFlags.FreshObjectLiteral | TypeFlags.ContainsObjectLiteral | (typeFlags & TypeFlags.PropagatingFlags);
71077108
return result;
71087109

71097110
function getIndexType(kind: IndexKind) {

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,7 @@ namespace ts {
17841784
/* @internal */
17851785
RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral,
17861786
/* @internal */
1787-
ContainsLiteralFlags = ContainsUndefinedOrNull | ContainsObjectLiteral | ContainsAnyFunctionType
1787+
PropagatingFlags = ContainsUndefinedOrNull | ContainsObjectLiteral | ContainsAnyFunctionType
17881788
}
17891789

17901790
// Properties common to all types

0 commit comments

Comments
 (0)