@@ -17175,7 +17175,8 @@ namespace ts {
1717517175
1717617176 let errorInfo: DiagnosticMessageChain | undefined;
1717717177 let relatedInfo: [DiagnosticRelatedInformation, ...DiagnosticRelatedInformation[]] | undefined;
17178- let maybeKeys: string[];
17178+ let maybeKeyList: string[];
17179+ let maybeKeySet: Set<string>;
1717917180 let sourceStack: Type[];
1718017181 let targetStack: Type[];
1718117182 let maybeCount = 0;
@@ -18024,8 +18025,9 @@ namespace ts {
1802418025 return entry & RelationComparisonResult.Succeeded ? Ternary.True : Ternary.False;
1802518026 }
1802618027 }
18027- if (!maybeKeys) {
18028- maybeKeys = [];
18028+ if (!maybeKeyList) {
18029+ maybeKeyList = [];
18030+ maybeKeySet = new Set<string>();
1802918031 sourceStack = [];
1803018032 targetStack = [];
1803118033 }
@@ -18037,20 +18039,19 @@ namespace ts {
1803718039 const index = length(id.slice(0, offset).match(/[-=]/g) || undefined);
1803818040 return `=${index}`;
1803918041 })).join(",");
18040- for (let i = 0; i < maybeCount; i++ ) {
18042+ if (maybeKeySet.has(id) || maybeKeySet.has(broadestEquivalentId) ) {
1804118043 // If source and target are already being compared, consider them related with assumptions
18042- if (id === maybeKeys[i] || broadestEquivalentId === maybeKeys[i]) {
18043- return Ternary.Maybe;
18044- }
18044+ return Ternary.Maybe;
1804518045 }
1804618046 if (depth === 100) {
1804718047 overflow = true;
1804818048 return Ternary.False;
1804918049 }
1805018050 }
1805118051 const maybeStart = maybeCount;
18052- maybeKeys [maybeCount] = id;
18052+ maybeKeyList [maybeCount] = id;
1805318053 maybeCount++;
18054+ maybeKeySet.add(id);
1805418055 sourceStack[depth] = source;
1805518056 targetStack[depth] = target;
1805618057 depth++;
@@ -18083,22 +18084,27 @@ namespace ts {
1808318084 }
1808418085 expandingFlags = saveExpandingFlags;
1808518086 depth--;
18086- if (result) {
18087- if (result === Ternary.True || depth === 0) {
18088- if (result === Ternary.True || result === Ternary.Maybe) {
18089- // If result is definitely true, record all maybe keys as having succeeded. Also, record Ternary.Maybe
18090- // results as having succeeded once we reach depth 0, but never record Ternary.Unknown results.
18091- for (let i = maybeStart; i < maybeCount; i++) {
18092- relation.set(maybeKeys[i], RelationComparisonResult.Succeeded | propagatingVarianceFlags);
18093- }
18087+ if (result === Ternary.True || result === Ternary.False || depth === 0) {
18088+ if (result === Ternary.True || result === Ternary.Maybe) {
18089+ // If result is definitely true, record all maybe keys as having succeeded. Also, record Ternary.Maybe
18090+ // results as having succeeded once we reach depth 0, but never record Ternary.Unknown results.
18091+ for (let i = maybeStart; i < maybeCount; i++) {
18092+ relation.set(maybeKeyList[i], RelationComparisonResult.Succeeded | propagatingVarianceFlags);
18093+ }
18094+ }
18095+ else if (result === Ternary.False) {
18096+ // A false result goes straight into global cache (when something is false under
18097+ // assumptions it will also be false without assumptions)
18098+ relation.set(id, (reportErrors ? RelationComparisonResult.Reported : 0) | RelationComparisonResult.Failed | propagatingVarianceFlags);
18099+ }
18100+ if (maybeStart === 0) {
18101+ maybeKeySet.clear();
18102+ }
18103+ else {
18104+ for (let i = maybeStart; i < maybeCount; i++) {
18105+ maybeKeySet.delete(maybeKeyList[i]);
1809418106 }
18095- maybeCount = maybeStart;
1809618107 }
18097- }
18098- else {
18099- // A false result goes straight into global cache (when something is false under
18100- // assumptions it will also be false without assumptions)
18101- relation.set(id, (reportErrors ? RelationComparisonResult.Reported : 0) | RelationComparisonResult.Failed | propagatingVarianceFlags);
1810218108 maybeCount = maybeStart;
1810318109 }
1810418110 return result;
0 commit comments