Skip to content

Commit 0436cfc

Browse files
committed
Do not report multiple diagnostics per signature.
If there are multiple diagnostics per signature, choose the signature with the fewer diagnostics to report. If there are more than one with the minimum, choose the latest in the overload set.
1 parent c0ff286 commit 0436cfc

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

src/compiler/checker.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21632,19 +21632,29 @@ namespace ts {
2163221632
}
2163321633
}
2163421634
else {
21635-
const related: DiagnosticRelatedInformation[] = [];
21635+
const allDiagnostics: DiagnosticRelatedInformation[][] = [];
21636+
let max = 0;
21637+
let min = Number.MAX_VALUE;
21638+
let minIndex = 0;
2163621639
let i = 0;
2163721640
for (const c of candidatesForArgumentError) {
21638-
i++;
21639-
const chain = () => chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Overload_0_of_1_2_gave_the_following_error, i, candidates.length, signatureToString(c));
21641+
const chain = () => chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Overload_0_of_1_2_gave_the_following_error, i + 1, candidates.length, signatureToString(c));
2164021642
const diags = getSignatureApplicabilityError(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, chain);
2164121643
if (diags) {
21642-
related.push(...diags);
21644+
if (diags.length <= min) {
21645+
min = diags.length;
21646+
minIndex = i;
21647+
}
21648+
max = Math.max(max, diags.length);
21649+
allDiagnostics.push(diags);
2164321650
}
2164421651
else {
2164521652
Debug.fail("No error for 3 or fewer overload signatures");
2164621653
}
21654+
i++;
2164721655
}
21656+
21657+
const related = max > 1 ? allDiagnostics[minIndex] : flatten(allDiagnostics);
2164821658
diagnostics.add(createDiagnosticForNodeFromMessageChain(node, chainDiagnosticMessages(/*details*/ undefined, Diagnostics.No_overload_matches_this_call), related));
2164921659
}
2165021660
}

src/compiler/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ namespace ts {
600600
*
601601
* @param array The array to flatten.
602602
*/
603+
export function flatten<T>(array: T[][]): T[];
603604
export function flatten<T>(array: ReadonlyArray<T | ReadonlyArray<T> | undefined>): T[];
604605
export function flatten<T>(array: ReadonlyArray<T | ReadonlyArray<T> | undefined> | undefined): T[] | undefined;
605606
export function flatten<T>(array: ReadonlyArray<T | ReadonlyArray<T> | undefined> | undefined): T[] | undefined {

src/compiler/diagnosticMessages.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,14 +2625,6 @@
26252625
"category": "Error",
26262626
"code": 2755
26272627
},
2628-
"The closest overload gave the following error.": {
2629-
"category": "Error",
2630-
"code": 2756
2631-
},
2632-
"The closest overload is declared here.": {
2633-
"category": "Error",
2634-
"code": 2757
2635-
},
26362628
"The last overload gave the following error.": {
26372629
"category": "Error",
26382630
"code": 2758

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8092,7 +8092,7 @@ namespace ts {
80928092
visitDirectory(basePath, combinePaths(currentDirectory, basePath), depth);
80938093
}
80948094

8095-
return flatten<string>(results);
8095+
return flatten(results);
80968096

80978097
function visitDirectory(path: string, absolutePath: string, depth: number | undefined) {
80988098
const canonicalPath = toCanonical(realpath(absolutePath));

tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,5 @@ tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,9): error TS2755: No ov
1515
!!! error TS2755: No overload matches this call.
1616
!!! related TS2760 tests/cases/compiler/heterogeneousArrayAndOverloads.ts:9:26: Overload 1 of 2, '(arg1: number[]): any', gave the following error.
1717
Type 'string' is not assignable to type 'number'.
18-
!!! related TS2760 tests/cases/compiler/heterogeneousArrayAndOverloads.ts:9:20: Overload 2 of 2, '(arg1: string[]): any', gave the following error.
19-
Type 'number' is not assignable to type 'string'.
20-
!!! related TS2760 tests/cases/compiler/heterogeneousArrayAndOverloads.ts:9:23: Overload 2 of 2, '(arg1: string[]): any', gave the following error.
21-
Type 'number' is not assignable to type 'string'.
22-
!!! related TS2760 tests/cases/compiler/heterogeneousArrayAndOverloads.ts:9:32: Overload 2 of 2, '(arg1: string[]): any', gave the following error.
23-
Type 'number' is not assignable to type 'string'.
2418
}
2519
}

0 commit comments

Comments
 (0)