Skip to content

Commit b11c9c8

Browse files
committed
Remove SymbolLinks.typeChecked
1 parent c777d5c commit b11c9c8

File tree

6 files changed

+69
-26
lines changed

6 files changed

+69
-26
lines changed

src/compiler/checker.ts

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,13 @@ module ts {
415415
}
416416

417417
function getExportAssignmentSymbol(symbol: Symbol): Symbol {
418-
if (!symbol.exportAssignSymbol) {
419-
var exportInformation = collectExportInformationForSourceFileOrModule(symbol);
418+
checkAndStoreTypeOfExportAssignmentSymbol(symbol);
419+
return symbol.exportAssignSymbol === unknownSymbol ? undefined : symbol.exportAssignSymbol;
420+
}
421+
422+
function checkAndStoreTypeOfExportAssignmentSymbol(containerSymbol: Symbol): void {
423+
if (!containerSymbol.exportAssignSymbol) {
424+
var exportInformation = collectExportInformationForSourceFileOrModule(containerSymbol);
420425
if (exportInformation.exportAssignments.length) {
421426
if (exportInformation.exportAssignments.length > 1) {
422427
// TypeScript 1.0 spec (April 2014): 11.2.4
@@ -436,9 +441,8 @@ module ts {
436441
var exportSymbol = resolveName(node, node.exportName.text, meaning, Diagnostics.Cannot_find_name_0, identifierToString(node.exportName));
437442
}
438443
}
439-
symbol.exportAssignSymbol = exportSymbol || unknownSymbol;
444+
containerSymbol.exportAssignSymbol = exportSymbol || unknownSymbol;
440445
}
441-
return symbol.exportAssignSymbol === unknownSymbol ? undefined : symbol.exportAssignSymbol;
442446
}
443447

444448
function collectExportInformationForSourceFileOrModule(symbol: Symbol) {
@@ -504,8 +508,12 @@ module ts {
504508
var declarations = symbol.declarations;
505509
for (var i = 0; i < declarations.length; i++) {
506510
var declaration = declarations[i];
507-
if (declaration.kind === kind) return declaration;
511+
if (declaration.kind === kind) {
512+
return declaration;
513+
}
508514
}
515+
516+
return undefined;
509517
}
510518

511519
function findConstructorDeclaration(node: ClassDeclaration): ConstructorDeclaration {
@@ -922,6 +930,12 @@ module ts {
922930

923931
function getTypeOfAccessors(symbol: Symbol): Type {
924932
var links = getSymbolLinks(symbol);
933+
checkAndStoreTypeOfAccessors(symbol, links);
934+
return links.type;
935+
}
936+
937+
function checkAndStoreTypeOfAccessors(symbol: Symbol, links?: SymbolLinks) {
938+
links = links || getSymbolLinks(symbol);
925939
if (!links.type) {
926940
links.type = resolvingType;
927941
var getter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.GetAccessor);
@@ -955,7 +969,6 @@ module ts {
955969
}
956970
}
957971
}
958-
959972

960973
if (links.type === resolvingType) {
961974
links.type = type;
@@ -964,7 +977,6 @@ module ts {
964977
else if (links.type === resolvingType) {
965978
links.type = anyType;
966979
}
967-
return links.type;
968980
}
969981

970982
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
@@ -4212,11 +4224,10 @@ module ts {
42124224
checkSourceElement(node.body);
42134225

42144226
var symbol = getSymbolOfNode(node);
4215-
var symbolLinks = getSymbolLinks(symbol);
4216-
var type = getTypeOfSymbol(symbol.parent);
4217-
if (!(symbolLinks.typeChecked)) {
4227+
var firstDeclaration = getDeclarationOfKind(symbol, node.kind);
4228+
// Only type check the symbol once
4229+
if (node === firstDeclaration) {
42184230
checkFunctionOrConstructorSymbol(symbol);
4219-
symbolLinks.typeChecked = true;
42204231
}
42214232

42224233
// exit early in the case of signature - super checks are not relevant to them
@@ -4335,6 +4346,7 @@ module ts {
43354346
}
43364347

43374348
checkFunctionDeclaration(node);
4349+
checkAndStoreTypeOfAccessors(getSymbolOfNode(node));
43384350
}
43394351

43404352
function checkTypeReference(node: TypeReferenceNode) {
@@ -4550,12 +4562,12 @@ module ts {
45504562
function checkFunctionDeclaration(node: FunctionDeclaration) {
45514563
checkDeclarationModifiers(node);
45524564
checkSignatureDeclaration(node);
4565+
45534566
var symbol = getSymbolOfNode(node);
4554-
var symbolLinks = getSymbolLinks(symbol);
4555-
var type = getTypeOfSymbol(symbol);
4556-
if (!(symbolLinks.typeChecked)) {
4567+
var firstDeclaration = getDeclarationOfKind(symbol, node.kind);
4568+
// Only type check the symbol once
4569+
if (node === firstDeclaration) {
45574570
checkFunctionOrConstructorSymbol(symbol);
4558-
symbolLinks.typeChecked = true;
45594571
}
45604572
checkSourceElement(node.body);
45614573

@@ -5156,15 +5168,15 @@ module ts {
51565168
checkNameIsReserved(node.name, Diagnostics.Interface_name_cannot_be_0);
51575169
checkTypeParameters(node.typeParameters);
51585170
var symbol = getSymbolOfNode(node);
5171+
var firstInterfaceDecl = <InterfaceDeclaration>getDeclarationOfKind(symbol, SyntaxKind.InterfaceDeclaration);
51595172
if (symbol.declarations.length > 1) {
5160-
var firstInterfaceDecl = <InterfaceDeclaration>getDeclarationOfKind(symbol, SyntaxKind.InterfaceDeclaration);
51615173
if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) {
51625174
error(node.name, Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters);
51635175
}
51645176
}
51655177

5166-
var links = getSymbolLinks(symbol);
5167-
if (!links.typeChecked) {
5178+
// Only check this symbol once
5179+
if (node === firstInterfaceDecl) {
51685180
var type = <InterfaceType>getDeclaredTypeOfSymbol(symbol);
51695181
// run subsequent checks only if first set succeeded
51705182
if (checkInheritedPropertiesAreIdentical(type, node.name)) {
@@ -5173,7 +5185,6 @@ module ts {
51735185
});
51745186
checkIndexConstraints(type);
51755187
}
5176-
links.typeChecked = true;
51775188
}
51785189
forEach(node.baseTypes, checkTypeReference);
51795190
forEach(node.members, checkSourceElement);
@@ -5237,11 +5248,6 @@ module ts {
52375248
error(node, Diagnostics.Ambient_external_module_declaration_cannot_specify_relative_module_name);
52385249
}
52395250
var symbol = getSymbolOfNode(node);
5240-
var links = getSymbolLinks(symbol);
5241-
if (!links.typeChecked) {
5242-
getExportAssignmentSymbol(symbol);
5243-
links.typeChecked = true;
5244-
}
52455251
}
52465252
checkSourceElement(node.body);
52475253
}
@@ -5310,6 +5316,11 @@ module ts {
53105316
if (container.kind === SyntaxKind.SourceFile) {
53115317
checkModulesEnabled(node);
53125318
}
5319+
else {
5320+
// In a module, the immediate parent will be a block, so climb up one more parent
5321+
container = container.parent;
5322+
}
5323+
checkAndStoreTypeOfExportAssignmentSymbol(getSymbolOfNode(container));
53135324
}
53145325

53155326
function checkSourceElement(node: Node): void {

src/compiler/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,6 @@ module ts {
693693
type?: Type; // Type of value symbol
694694
declaredType?: Type; // Type of class, interface, enum, or type parameter
695695
mapper?: TypeMapper; // Type mapper for instantiation alias
696-
typeChecked?: boolean; // True if symbol has been type checked
697696
referenced?: boolean; // True if alias symbol has been referenced as a value
698697
}
699698

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
==== tests/cases/compiler/functionAndInterfaceWithSeparateErrors.ts (2 errors) ====
2+
function Foo(s: string);
3+
~~~~~~~~~~~~~~~~~~~~~~~~
4+
!!! Overload signature is not compatible with function implementation.
5+
function Foo(n: number) { }
6+
7+
interface Foo {
8+
[s: string]: string;
9+
prop: number;
10+
~~~~~~~~~~~~~
11+
!!! Property 'prop' of type 'number' is not assignable to string index type 'string'.
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [functionAndInterfaceWithSeparateErrors.ts]
2+
function Foo(s: string);
3+
function Foo(n: number) { }
4+
5+
interface Foo {
6+
[s: string]: string;
7+
prop: number;
8+
}
9+
10+
//// [functionAndInterfaceWithSeparateErrors.js]
11+
function Foo(n) {
12+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
==== tests/cases/conformance/parser/ecmascript5/ExportAssignments/parserExportAssignment5.ts (1 errors) ====
1+
==== tests/cases/conformance/parser/ecmascript5/ExportAssignments/parserExportAssignment5.ts (2 errors) ====
22
module M {
33
export = A;
44
~~~~~~~~~~~
55
!!! An export assignment cannot be used in an internal module.
6+
~~~~~~~~~~~
7+
!!! Cannot find name 'A'.
68
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function Foo(s: string);
2+
function Foo(n: number) { }
3+
4+
interface Foo {
5+
[s: string]: string;
6+
prop: number;
7+
}

0 commit comments

Comments
 (0)