Skip to content

Commit f45c2e2

Browse files
committed
Use newly freed up object flags to limit member setting, fix crash with those object flags
1 parent 5e6dcea commit f45c2e2

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/compiler/checker.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11857,7 +11857,7 @@ namespace ts {
1185711857
}
1185811858

1185911859
function elaborateNeverIntersection(errorInfo: DiagnosticMessageChain | undefined, type: Type) {
11860-
if (getObjectFlags(type) & ObjectFlags.IsNeverIntersection) {
11860+
if (type.flags & TypeFlags.Intersection && getObjectFlags(type) & ObjectFlags.IsNeverIntersection) {
1186111861
const neverProp = find(getPropertiesOfUnionOrIntersectionType(<IntersectionType>type), isDiscriminantWithNeverType);
1186211862
if (neverProp) {
1186311863
return chainDiagnosticMessages(errorInfo, Diagnostics.The_intersection_0_was_reduced_to_never_because_property_1_has_conflicting_types_in_some_constituents,
@@ -17178,12 +17178,13 @@ namespace ts {
1717817178

1717917179
function getNormalizedType(type: Type, writing: boolean): Type {
1718017180
while (true) {
17181-
const t = getSingleBaseForNonAugmentingSubtypeOrType(isFreshLiteralType(type) ? (<FreshableType>type).regularType :
17181+
let t = isFreshLiteralType(type) ? (<FreshableType>type).regularType :
1718217182
getObjectFlags(type) & ObjectFlags.Reference && (<TypeReference>type).node ? createTypeReference((<TypeReference>type).target, getTypeArguments(<TypeReference>type)) :
1718317183
type.flags & TypeFlags.UnionOrIntersection ? getReducedType(type) :
1718417184
type.flags & TypeFlags.Substitution ? writing ? (<SubstitutionType>type).baseType : (<SubstitutionType>type).substitute :
1718517185
type.flags & TypeFlags.Simplifiable ? getSimplifiedType(type, writing) :
17186-
type);
17186+
type;
17187+
t = getSingleBaseForNonAugmentingSubtype(t) || t;
1718717188
if (t === type) break;
1718817189
type = t;
1718917190
}
@@ -17685,8 +17686,8 @@ namespace ts {
1768517686

1768617687
function reportErrorResults(source: Type, target: Type, result: Ternary, isComparingJsxAttributes: boolean) {
1768717688
if (!result && reportErrors) {
17688-
const sourceHasBase = getSingleBaseForNonAugmentingSubtypeOrType(originalSource) !== originalSource;
17689-
const targetHasBase = getSingleBaseForNonAugmentingSubtypeOrType(originalTarget) !== originalTarget;
17689+
const sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
17690+
const targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
1769017691
source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
1769117692
target = (originalTarget.aliasSymbol || targetHasBase) ? originalTarget : target;
1769217693
let maybeSuppress = overrideNextErrorInfo > 0;
@@ -19941,26 +19942,28 @@ namespace ts {
1994119942
return isArrayType(type) || !(type.flags & TypeFlags.Nullable) && isTypeAssignableTo(type, anyReadonlyArrayType);
1994219943
}
1994319944

19944-
function getSingleBaseForNonAugmentingSubtypeOrType(type: Type) {
19945+
function getSingleBaseForNonAugmentingSubtype(type: Type) {
1994519946
if (!(getObjectFlags(type) & ObjectFlags.Reference) || !(getObjectFlags((type as TypeReference).target) & ObjectFlags.ClassOrInterface)) {
19946-
return type;
19947+
return undefined;
1994719948
}
19948-
if ((type as TypeReference).cachedEquivalentBaseTypeOrSelf) {
19949-
return (type as TypeReference).cachedEquivalentBaseTypeOrSelf!;
19949+
if (getObjectFlags(type) & ObjectFlags.IdenticalBaseTypeCalculated) {
19950+
return getObjectFlags(type) & ObjectFlags.IdenticalBaseTypeExists ? (type as TypeReference).cachedEquivalentBaseType : undefined;
1995019951
}
19952+
(type as TypeReference).objectFlags |= ObjectFlags.IdenticalBaseTypeCalculated;
1995119953
const target = (type as TypeReference).target as InterfaceType;
1995219954
const bases = getBaseTypes(target);
1995319955
if (bases.length !== 1) {
19954-
return (type as TypeReference).cachedEquivalentBaseTypeOrSelf = type;
19956+
return undefined;
1995519957
}
1995619958
if (getMembersOfSymbol(type.symbol).size) {
19957-
return (type as TypeReference).cachedEquivalentBaseTypeOrSelf = type; // If the interface has any members, they may subtype members in the base, so we should do a full structural comparison
19959+
return undefined; // If the interface has any members, they may subtype members in the base, so we should do a full structural comparison
1995819960
}
1995919961
let instantiatedBase = !length(target.typeParameters) ? bases[0] : instantiateType(bases[0], createTypeMapper(target.typeParameters!, getTypeArguments(type as TypeReference).slice(0, target.typeParameters!.length)));
1996019962
if (length(getTypeArguments(type as TypeReference)) > length(target.typeParameters)) {
1996119963
instantiatedBase = getTypeWithThisArgument(instantiatedBase, last(getTypeArguments(type as TypeReference)));
1996219964
}
19963-
return (type as TypeReference).cachedEquivalentBaseTypeOrSelf = instantiatedBase;
19965+
(type as TypeReference).objectFlags |= ObjectFlags.IdenticalBaseTypeExists;
19966+
return (type as TypeReference).cachedEquivalentBaseType = instantiatedBase;
1996419967
}
1996519968

1996619969
function isEmptyArrayLiteralType(type: Type): boolean {

src/compiler/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5219,6 +5219,12 @@ namespace ts {
52195219
IsNeverIntersectionComputed = 1 << 26, // IsNeverLike flag has been computed
52205220
/* @internal */
52215221
IsNeverIntersection = 1 << 27, // Intersection reduces to never
5222+
5223+
// Flags that require TypeFlags.Reference
5224+
/* @internal */
5225+
IdenticalBaseTypeCalculated = 1 << 26, // has had `getSingleBaseForNonAugmentingSubtype` invoked on it already
5226+
/* @internal */
5227+
IdenticalBaseTypeExists = 1 << 27, // has a defined cachedEquivalentBaseType member
52225228
}
52235229

52245230
/* @internal */
@@ -5281,7 +5287,7 @@ namespace ts {
52815287
/* @internal */
52825288
literalType?: TypeReference; // Clone of type with ObjectFlags.ArrayLiteral set
52835289
/* @internal */
5284-
cachedEquivalentBaseTypeOrSelf?: Type; // Only set on references to class or interfaces with a single base type and no augmentations
5290+
cachedEquivalentBaseType?: Type; // Only set on references to class or interfaces with a single base type and no augmentations
52855291
}
52865292

52875293
export interface DeferredTypeReference extends TypeReference {

0 commit comments

Comments
 (0)