@@ -20619,30 +20619,37 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2061920619 if (sourceValue !== targetValue) {
2062020620 const sourceIsString = typeof sourceValue === "string";
2062120621 const targetIsString = typeof targetValue === "string";
20622- let errorFlags: RelationComparisonResult = errorReporter ? RelationComparisonResult.Reported : RelationComparisonResult.None;
2062320622
2062420623 if (sourceValue !== undefined && targetValue !== undefined) {
20625- // If we have 2 *known* values that differ, we should report an error.
20626- const escapedSource = sourceIsString ? `"${escapeString(sourceValue)}"` : sourceValue;
20627- const escapedTarget = targetIsString ? `"${escapeString(targetValue)}"` : targetValue;
20628- errorReporter?.(Diagnostics.Each_declaration_of_0_1_differs_in_its_value_where_2_was_expected_but_3_was_given, symbolName(targetSymbol), symbolName(targetProperty), escapedTarget, escapedSource);
20629- errorFlags |= RelationComparisonResult.Failed;
20624+ // If we have 2 enums with *known* values that differ, they are incompatible.
20625+ if (!errorReporter) {
20626+ enumRelation.set(id, RelationComparisonResult.Failed);
20627+ }
20628+ else {
20629+ const escapedSource = sourceIsString ? `"${escapeString(sourceValue)}"` : sourceValue;
20630+ const escapedTarget = targetIsString ? `"${escapeString(targetValue)}"` : targetValue;
20631+ errorReporter(Diagnostics.Each_declaration_of_0_1_differs_in_its_value_where_2_was_expected_but_3_was_given, symbolName(targetSymbol), symbolName(targetProperty), escapedTarget, escapedSource);
20632+ enumRelation.set(id, RelationComparisonResult.Failed | RelationComparisonResult.Reported);
20633+ }
20634+ return false;
2063020635 }
2063120636 else if (sourceIsString || targetIsString) {
2063220637 // At this point we know that at least one of the values is 'undefined'.
2063320638 // This may mean that we have an opaque member from an ambient enum declaration,
2063420639 // or that we were not able to calculate it (which is basically an error).
2063520640 //
2063620641 // Either way, we can assume that it's numeric.
20637- // If we have a string, we report a mismatch in the types.
20638- const knownStringValue = (sourceValue ?? targetValue) as string;
20639- const escapedValue = `"${escapeString(knownStringValue)}"`;
20640- errorReporter?.(Diagnostics.One_value_of_0_1_is_the_string_2_and_the_other_is_assumed_to_be_an_unknown_numeric_value, symbolName(targetSymbol), symbolName(targetProperty), escapedValue);
20641- errorFlags |= RelationComparisonResult.Failed;
20642- }
20643-
20644- if (errorFlags & RelationComparisonResult.Failed) {
20645- enumRelation.set(id, errorFlags);
20642+ // If the other is a string, we have a mismatch in types.
20643+ if (!errorReporter) {
20644+ enumRelation.set(id, RelationComparisonResult.Failed);
20645+ }
20646+ else {
20647+ const knownStringValue = sourceValue ?? targetValue;
20648+ Debug.assert(typeof knownStringValue === "string");
20649+ const escapedValue = `"${escapeString(knownStringValue)}"`;
20650+ errorReporter(Diagnostics.One_value_of_0_1_is_the_string_2_and_the_other_is_assumed_to_be_an_unknown_numeric_value, symbolName(targetSymbol), symbolName(targetProperty), escapedValue);
20651+ enumRelation.set(id, RelationComparisonResult.Failed | RelationComparisonResult.Reported);
20652+ }
2064620653 return false;
2064720654 }
2064820655 }
0 commit comments