From d224286d59554a40e8ded19a25a96b87f97fd1e9 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 29 Jan 2015 14:37:57 -0800 Subject: [PATCH] Address CR feedback --- src/compiler/checker.ts | 21 +++++++-------------- src/compiler/types.ts | 6 +++--- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c2e79bdafe7..ed89032b781 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3453,7 +3453,7 @@ module ts { var errorInfo: DiagnosticMessageChain; var sourceStack: ObjectType[]; var targetStack: ObjectType[]; - var maybeStack: Map[]; + var maybeStack: Map[]; var expandingFlags: number; var depth = 0; var overflow = false; @@ -3471,7 +3471,7 @@ module ts { // where errors were being reported. if (errorInfo.next === undefined) { errorInfo = undefined; - isRelatedTo(source, target, errorNode !== undefined, headMessage, /* mustRecompute */ true); + isRelatedTo(source, target, errorNode !== undefined, headMessage, /* elaborateErrors */ true); } if (containingMessageChain) { errorInfo = concatenateDiagnosticMessageChains(containingMessageChain, errorInfo); @@ -3488,7 +3488,7 @@ module ts { // Ternary.True if they are related with no assumptions, // Ternary.Maybe if they are related with assumptions of other relationships, or // Ternary.False if they are not related. - function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage, mustRecompute = false): Ternary { + function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage, elaborateErrors = false): Ternary { var result: Ternary; // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return Ternary.True; @@ -3555,7 +3555,7 @@ module ts { // identity relation does not use apparent type var sourceOrApparentType = relation === identityRelation ? source : getApparentType(source); if (sourceOrApparentType.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType && - (result = objectTypeRelatedTo(sourceOrApparentType, target, reportStructuralErrors, mustRecompute))) { + (result = objectTypeRelatedTo(sourceOrApparentType, target, reportStructuralErrors, elaborateErrors))) { errorInfo = saveErrorInfo; return result; } @@ -3681,7 +3681,7 @@ module ts { sourceStack[depth] = source; targetStack[depth] = target; maybeStack[depth] = {}; - maybeStack[depth][id] = true; + maybeStack[depth][id] = RelationComparisonResult.Succeeded; depth++; var saveExpandingFlags = expandingFlags; if (!(expandingFlags & 1) && isDeeplyNestedGeneric(source, sourceStack)) expandingFlags |= 1; @@ -3709,15 +3709,8 @@ module ts { if (result) { var maybeCache = maybeStack[depth]; // If result is definitely true, copy assumptions to global cache, else copy to next level up - if (result === Ternary.True || depth === 0) { - var key: string; - for (key in maybeCache) { - relation[key] = maybeCache[key] ? RelationComparisonResult.Succeeded : (reportErrors ? RelationComparisonResult.FailedAndReported : RelationComparisonResult.Failed); - } - } - else { - copyMap(maybeCache, maybeStack[depth - 1]); - } + var destinationCache = (result === Ternary.True || depth === 0) ? relation : maybeStack[depth - 1]; + copyMap(maybeCache, destinationCache); } else { // A false result goes straight into global cache (when something is false under assumptions it diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 57266fc5a89..80bdc875177 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -331,9 +331,9 @@ module ts { } export const enum RelationComparisonResult { - Succeeded = 0, - Failed = 1, - FailedAndReported = 2 + Succeeded = 1, // Should be truthy + Failed = 2, + FailedAndReported = 3 } export interface Node extends TextRange {