Skip to content

Commit c6c346e

Browse files
authored
Partially fix multi-checker diagnostics consistency (#2134)
1 parent 183d674 commit c6c346e

File tree

4 files changed

+64
-15
lines changed

4 files changed

+64
-15
lines changed

internal/checker/checker.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4271,7 +4271,7 @@ func (c *Checker) checkClassLikeDeclaration(node *ast.Node) {
42714271
}
42724272
c.checkIndexConstraints(classType, symbol, false /*isStaticIndex*/)
42734273
c.checkIndexConstraints(staticType, symbol, true /*isStaticIndex*/)
4274-
c.checkTypeForDuplicateIndexSignatures(node)
4274+
c.checkClassOrInterfaceForDuplicateIndexSignatures(node)
42754275
c.checkPropertyInitialization(node)
42764276
}
42774277

@@ -4758,14 +4758,15 @@ func (c *Checker) checkIndexConstraintForIndexSignature(t *Type, checkInfo *Inde
47584758
}
47594759
}
47604760

4761-
func (c *Checker) checkTypeForDuplicateIndexSignatures(node *ast.Node) {
4762-
if ast.IsInterfaceDeclaration(node) {
4763-
// in case of merging interface declaration it is possible that we'll enter this check procedure several times for every declaration
4764-
// to prevent this run check only for the first declaration of a given kind
4765-
if symbol := c.getSymbolOfDeclaration(node); len(symbol.Declarations) != 0 && symbol.Declarations[0] != node {
4766-
return
4767-
}
4761+
func (c *Checker) checkClassOrInterfaceForDuplicateIndexSignatures(node *ast.Node) {
4762+
// Only check the type once
4763+
if links := c.declaredTypeLinks.Get(c.getSymbolOfDeclaration(node)); !links.indexSignaturesChecked {
4764+
links.indexSignaturesChecked = true
4765+
c.checkTypeForDuplicateIndexSignatures(node)
47684766
}
4767+
}
4768+
4769+
func (c *Checker) checkTypeForDuplicateIndexSignatures(node *ast.Node) {
47694770
// TypeScript 1.0 spec (April 2014)
47704771
// 3.7.4: An object type can contain at most one string index signature and one numeric index signature.
47714772
// 8.5: A class declaration can have at most one string index member declaration and one numeric index member declaration
@@ -4865,8 +4866,8 @@ func (c *Checker) checkInterfaceDeclaration(node *ast.Node) {
48654866
symbol := c.getSymbolOfDeclaration(node)
48664867
c.checkTypeParameterListsIdentical(symbol)
48674868
// Only check this symbol once
4868-
firstInterfaceDecl := ast.GetDeclarationOfKind(symbol, ast.KindInterfaceDeclaration)
4869-
if node == firstInterfaceDecl {
4869+
if links := c.declaredTypeLinks.Get(symbol); !links.interfaceChecked {
4870+
links.interfaceChecked = true
48704871
t := c.getDeclaredTypeOfSymbol(symbol)
48714872
typeWithThis := c.getTypeWithThisArgument(t, nil, false)
48724873
// run subsequent checks only if first set succeeded
@@ -4886,7 +4887,7 @@ func (c *Checker) checkInterfaceDeclaration(node *ast.Node) {
48864887
c.checkTypeReferenceNode(heritageElement)
48874888
}
48884889
c.checkSourceElements(node.Members())
4889-
c.checkTypeForDuplicateIndexSignatures(node)
4890+
c.checkClassOrInterfaceForDuplicateIndexSignatures(node)
48904891
c.registerForUnusedIdentifiersCheck(node)
48914892
}
48924893

internal/checker/types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ type TypeAliasLinks struct {
193193
// Links for declared types (type parameters, class types, interface types, enums)
194194

195195
type DeclaredTypeLinks struct {
196-
declaredType *Type
197-
typeParametersChecked bool
196+
declaredType *Type
197+
interfaceChecked bool
198+
indexSignaturesChecked bool
199+
typeParametersChecked bool
198200
}
199201

200202
// Links for switch clauses

testdata/baselines/reference/submodule/conformance/1.0lib-noErrors.errors.txt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
1.0lib-noErrors.ts(92,5): error TS2374: Duplicate index signature for type 'string'.
12
1.0lib-noErrors.ts(130,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'Object' must be of type 'ObjectConstructor', but here has type '{ (): any; (value: any): any; new (value?: any): Object; prototype: Object; getPrototypeOf(o: any): any; getOwnPropertyDescriptor(o: any, p: string): PropertyDescriptor; getOwnPropertyNames(o: any): string[]; create(o: any, properties?: PropertyDescriptorMap): any; defineProperty(o: any, p: string, attributes: PropertyDescriptor): any; defineProperties(o: any, properties: PropertyDescriptorMap): any; seal(o: any): any; freeze(o: any): any; preventExtensions(o: any): any; isSealed(o: any): boolean; isFrozen(o: any): boolean; isExtensible(o: any): boolean; keys(o: any): string[]; }'.
23
1.0lib-noErrors.ts(251,5): error TS2687: All declarations of 'length' must have identical modifiers.
34
1.0lib-noErrors.ts(258,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'Function' must be of type 'FunctionConstructor', but here has type '{ (...args: string[]): Function; new (...args: string[]): Function; prototype: Function; }'.
5+
1.0lib-noErrors.ts(269,5): error TS2374: Duplicate index signature for type 'number'.
46
1.0lib-noErrors.ts(414,5): error TS2687: All declarations of 'length' must have identical modifiers.
7+
1.0lib-noErrors.ts(424,5): error TS2374: Duplicate index signature for type 'number'.
58
1.0lib-noErrors.ts(430,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'String' must be of type 'StringConstructor', but here has type '{ (value?: any): string; new (value?: any): String; prototype: String; fromCharCode(...codes: number[]): string; }'.
69
1.0lib-noErrors.ts(439,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'Boolean' must be of type 'BooleanConstructor', but here has type '{ (value?: any): boolean; new (value?: any): Boolean; prototype: Boolean; }'.
710
1.0lib-noErrors.ts(472,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'Number' must be of type 'NumberConstructor', but here has type '{ (value?: any): number; new (value?: any): Number; prototype: Number; MAX_VALUE: number; MIN_VALUE: number; NaN: number; NEGATIVE_INFINITY: number; POSITIVE_INFINITY: number; }'.
@@ -14,6 +17,11 @@
1417
1.0lib-noErrors.ts(516,5): error TS2687: All declarations of 'SQRT1_2' must have identical modifiers.
1518
1.0lib-noErrors.ts(518,5): error TS2687: All declarations of 'SQRT2' must have identical modifiers.
1619
1.0lib-noErrors.ts(767,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'Date' must be of type 'DateConstructor', but here has type '{ (): string; new (): Date; new (value: number): Date; new (value: string): Date; new (year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date; prototype: Date; parse(s: string): number; UTC(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): number; now(): number; }'.
20+
1.0lib-noErrors.ts(793,11): error TS2430: Interface 'RegExpExecArray' incorrectly extends interface 'string[]'.
21+
Types of property 'concat' are incompatible.
22+
Type '(...items: string[][]) => string[]' is not assignable to type '{ (...items: ConcatArray<string>[]): string[]; (...items: (string | ConcatArray<string>)[]): string[]; <U extends string[]>(...items: U[]): string[]; (...items: string[]): string[]; }'.
23+
Types of parameters 'items' and 'items' are incompatible.
24+
Type 'string' is not assignable to type 'string[]'.
1725
1.0lib-noErrors.ts(840,5): error TS2687: All declarations of 'source' must have identical modifiers.
1826
1.0lib-noErrors.ts(843,5): error TS2687: All declarations of 'global' must have identical modifiers.
1927
1.0lib-noErrors.ts(846,5): error TS2687: All declarations of 'ignoreCase' must have identical modifiers.
@@ -26,10 +34,11 @@
2634
1.0lib-noErrors.ts(909,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'SyntaxError' must be of type 'SyntaxErrorConstructor', but here has type '{ (message?: string): SyntaxError; new (message?: string): SyntaxError; prototype: SyntaxError; }'.
2735
1.0lib-noErrors.ts(917,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'TypeError' must be of type 'TypeErrorConstructor', but here has type '{ (message?: string): TypeError; new (message?: string): TypeError; prototype: TypeError; }'.
2836
1.0lib-noErrors.ts(925,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'URIError' must be of type 'URIErrorConstructor', but here has type '{ (message?: string): URIError; new (message?: string): URIError; prototype: URIError; }'.
37+
1.0lib-noErrors.ts(1132,5): error TS2374: Duplicate index signature for type 'number'.
2938
1.0lib-noErrors.ts(1134,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'Array' must be of type 'ArrayConstructor', but here has type '{ (arrayLength?: number): any[]; <T>(arrayLength: number): T[]; <T>(...items: T[]): T[]; new (arrayLength?: number): any[]; new <T>(arrayLength: number): T[]; new <T>(...items: T[]): T[]; isArray(arg: any): boolean; prototype: any[]; }'.
3039

3140

32-
==== 1.0lib-noErrors.ts (29 errors) ====
41+
==== 1.0lib-noErrors.ts (34 errors) ====
3342
/* *****************************************************************************
3443
Copyright (c) Microsoft Corporation. All rights reserved.
3544
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
@@ -122,6 +131,8 @@
122131

123132
interface PropertyDescriptorMap {
124133
[s: string]: PropertyDescriptor;
134+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135+
!!! error TS2374: Duplicate index signature for type 'string'.
125136
}
126137

127138
interface Object {
@@ -307,6 +318,8 @@
307318

308319
interface IArguments {
309320
[index: number]: any;
321+
~~~~~~~~~~~~~~~~~~~~~
322+
!!! error TS2374: Duplicate index signature for type 'number'.
310323
length: number;
311324
callee: Function;
312325
}
@@ -464,6 +477,8 @@
464477
substr(from: number, length?: number): string;
465478

466479
[index: number]: string;
480+
~~~~~~~~~~~~~~~~~~~~~~~~
481+
!!! error TS2374: Duplicate index signature for type 'number'.
467482
}
468483

469484
/**
@@ -861,6 +876,12 @@
861876
}
862877

863878
interface RegExpExecArray {
879+
~~~~~~~~~~~~~~~
880+
!!! error TS2430: Interface 'RegExpExecArray' incorrectly extends interface 'string[]'.
881+
!!! error TS2430: Types of property 'concat' are incompatible.
882+
!!! error TS2430: Type '(...items: string[][]) => string[]' is not assignable to type '{ (...items: ConcatArray<string>[]): string[]; (...items: (string | ConcatArray<string>)[]): string[]; <U extends string[]>(...items: U[]): string[]; (...items: string[]): string[]; }'.
883+
!!! error TS2430: Types of parameters 'items' and 'items' are incompatible.
884+
!!! error TS2430: Type 'string' is not assignable to type 'string[]'.
864885
[index: number]: string;
865886
length: number;
866887

@@ -1232,6 +1253,8 @@
12321253
length: number;
12331254

12341255
[n: number]: T;
1256+
~~~~~~~~~~~~~~~
1257+
!!! error TS2374: Duplicate index signature for type 'number'.
12351258
}
12361259
declare var Array: {
12371260
~~~~~

testdata/baselines/reference/submodule/conformance/1.0lib-noErrors.errors.txt.diff

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
+++ new.1.0lib-noErrors.errors.txt
33
@@= skipped -0, +0 lines =@@
44
-<no content>
5+
+1.0lib-noErrors.ts(92,5): error TS2374: Duplicate index signature for type 'string'.
56
+1.0lib-noErrors.ts(130,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'Object' must be of type 'ObjectConstructor', but here has type '{ (): any; (value: any): any; new (value?: any): Object; prototype: Object; getPrototypeOf(o: any): any; getOwnPropertyDescriptor(o: any, p: string): PropertyDescriptor; getOwnPropertyNames(o: any): string[]; create(o: any, properties?: PropertyDescriptorMap): any; defineProperty(o: any, p: string, attributes: PropertyDescriptor): any; defineProperties(o: any, properties: PropertyDescriptorMap): any; seal(o: any): any; freeze(o: any): any; preventExtensions(o: any): any; isSealed(o: any): boolean; isFrozen(o: any): boolean; isExtensible(o: any): boolean; keys(o: any): string[]; }'.
67
+1.0lib-noErrors.ts(251,5): error TS2687: All declarations of 'length' must have identical modifiers.
78
+1.0lib-noErrors.ts(258,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'Function' must be of type 'FunctionConstructor', but here has type '{ (...args: string[]): Function; new (...args: string[]): Function; prototype: Function; }'.
9+
+1.0lib-noErrors.ts(269,5): error TS2374: Duplicate index signature for type 'number'.
810
+1.0lib-noErrors.ts(414,5): error TS2687: All declarations of 'length' must have identical modifiers.
11+
+1.0lib-noErrors.ts(424,5): error TS2374: Duplicate index signature for type 'number'.
912
+1.0lib-noErrors.ts(430,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'String' must be of type 'StringConstructor', but here has type '{ (value?: any): string; new (value?: any): String; prototype: String; fromCharCode(...codes: number[]): string; }'.
1013
+1.0lib-noErrors.ts(439,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'Boolean' must be of type 'BooleanConstructor', but here has type '{ (value?: any): boolean; new (value?: any): Boolean; prototype: Boolean; }'.
1114
+1.0lib-noErrors.ts(472,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'Number' must be of type 'NumberConstructor', but here has type '{ (value?: any): number; new (value?: any): Number; prototype: Number; MAX_VALUE: number; MIN_VALUE: number; NaN: number; NEGATIVE_INFINITY: number; POSITIVE_INFINITY: number; }'.
@@ -18,6 +21,11 @@
1821
+1.0lib-noErrors.ts(516,5): error TS2687: All declarations of 'SQRT1_2' must have identical modifiers.
1922
+1.0lib-noErrors.ts(518,5): error TS2687: All declarations of 'SQRT2' must have identical modifiers.
2023
+1.0lib-noErrors.ts(767,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'Date' must be of type 'DateConstructor', but here has type '{ (): string; new (): Date; new (value: number): Date; new (value: string): Date; new (year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date; prototype: Date; parse(s: string): number; UTC(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): number; now(): number; }'.
24+
+1.0lib-noErrors.ts(793,11): error TS2430: Interface 'RegExpExecArray' incorrectly extends interface 'string[]'.
25+
+ Types of property 'concat' are incompatible.
26+
+ Type '(...items: string[][]) => string[]' is not assignable to type '{ (...items: ConcatArray<string>[]): string[]; (...items: (string | ConcatArray<string>)[]): string[]; <U extends string[]>(...items: U[]): string[]; (...items: string[]): string[]; }'.
27+
+ Types of parameters 'items' and 'items' are incompatible.
28+
+ Type 'string' is not assignable to type 'string[]'.
2129
+1.0lib-noErrors.ts(840,5): error TS2687: All declarations of 'source' must have identical modifiers.
2230
+1.0lib-noErrors.ts(843,5): error TS2687: All declarations of 'global' must have identical modifiers.
2331
+1.0lib-noErrors.ts(846,5): error TS2687: All declarations of 'ignoreCase' must have identical modifiers.
@@ -30,10 +38,11 @@
3038
+1.0lib-noErrors.ts(909,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'SyntaxError' must be of type 'SyntaxErrorConstructor', but here has type '{ (message?: string): SyntaxError; new (message?: string): SyntaxError; prototype: SyntaxError; }'.
3139
+1.0lib-noErrors.ts(917,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'TypeError' must be of type 'TypeErrorConstructor', but here has type '{ (message?: string): TypeError; new (message?: string): TypeError; prototype: TypeError; }'.
3240
+1.0lib-noErrors.ts(925,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'URIError' must be of type 'URIErrorConstructor', but here has type '{ (message?: string): URIError; new (message?: string): URIError; prototype: URIError; }'.
41+
+1.0lib-noErrors.ts(1132,5): error TS2374: Duplicate index signature for type 'number'.
3342
+1.0lib-noErrors.ts(1134,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'Array' must be of type 'ArrayConstructor', but here has type '{ (arrayLength?: number): any[]; <T>(arrayLength: number): T[]; <T>(...items: T[]): T[]; new (arrayLength?: number): any[]; new <T>(arrayLength: number): T[]; new <T>(...items: T[]): T[]; isArray(arg: any): boolean; prototype: any[]; }'.
3443
+
3544
+
36-
+==== 1.0lib-noErrors.ts (29 errors) ====
45+
+==== 1.0lib-noErrors.ts (34 errors) ====
3746
+ /* *****************************************************************************
3847
+ Copyright (c) Microsoft Corporation. All rights reserved.
3948
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
@@ -126,6 +135,8 @@
126135
+
127136
+ interface PropertyDescriptorMap {
128137
+ [s: string]: PropertyDescriptor;
138+
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
139+
+!!! error TS2374: Duplicate index signature for type 'string'.
129140
+ }
130141
+
131142
+ interface Object {
@@ -311,6 +322,8 @@
311322
+
312323
+ interface IArguments {
313324
+ [index: number]: any;
325+
+ ~~~~~~~~~~~~~~~~~~~~~
326+
+!!! error TS2374: Duplicate index signature for type 'number'.
314327
+ length: number;
315328
+ callee: Function;
316329
+ }
@@ -468,6 +481,8 @@
468481
+ substr(from: number, length?: number): string;
469482
+
470483
+ [index: number]: string;
484+
+ ~~~~~~~~~~~~~~~~~~~~~~~~
485+
+!!! error TS2374: Duplicate index signature for type 'number'.
471486
+ }
472487
+
473488
+ /**
@@ -865,6 +880,12 @@
865880
+ }
866881
+
867882
+ interface RegExpExecArray {
883+
+ ~~~~~~~~~~~~~~~
884+
+!!! error TS2430: Interface 'RegExpExecArray' incorrectly extends interface 'string[]'.
885+
+!!! error TS2430: Types of property 'concat' are incompatible.
886+
+!!! error TS2430: Type '(...items: string[][]) => string[]' is not assignable to type '{ (...items: ConcatArray<string>[]): string[]; (...items: (string | ConcatArray<string>)[]): string[]; <U extends string[]>(...items: U[]): string[]; (...items: string[]): string[]; }'.
887+
+!!! error TS2430: Types of parameters 'items' and 'items' are incompatible.
888+
+!!! error TS2430: Type 'string' is not assignable to type 'string[]'.
868889
+ [index: number]: string;
869890
+ length: number;
870891
+
@@ -1236,6 +1257,8 @@
12361257
+ length: number;
12371258
+
12381259
+ [n: number]: T;
1260+
+ ~~~~~~~~~~~~~~~
1261+
+!!! error TS2374: Duplicate index signature for type 'number'.
12391262
+ }
12401263
+ declare var Array: {
12411264
+ ~~~~~

0 commit comments

Comments
 (0)