From 8922a090397aafd224ed7219f70c58d9eed3b71e Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 13 May 2015 17:45:09 -0700 Subject: [PATCH 1/2] Only call getTypeOfSymbol recursively if it's a value --- src/compiler/checker.ts | 5 ++++- src/harness/fourslashRunner.ts | 4 ++-- tests/cases/fourslash/aliasMergingWithNamespace.ts | 9 +++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/aliasMergingWithNamespace.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7728c7d68e..cb5bcbf0b7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2414,7 +2414,10 @@ module ts { function getTypeOfAlias(symbol: Symbol): Type { let links = getSymbolLinks(symbol); if (!links.type) { - links.type = getTypeOfSymbol(resolveAlias(symbol)); + let targetSymbol = resolveAlias(symbol); + links.type = targetSymbol.flags & SymbolFlags.Value + ? getTypeOfSymbol(targetSymbol) + : unknownType; } return links.type; } diff --git a/src/harness/fourslashRunner.ts b/src/harness/fourslashRunner.ts index 1ab6e31cdb..d11c5e639e 100644 --- a/src/harness/fourslashRunner.ts +++ b/src/harness/fourslashRunner.ts @@ -35,9 +35,9 @@ class FourSlashRunner extends RunnerBase { this.tests = this.enumerateFiles(this.basePath, /\.ts/i, { recursive: false }); } - describe(this.testSuiteName, () => { this.tests.forEach((fn: string) => { - fn = ts.normalizeSlashes(fn); + describe(fn, () => { + fn = ts.normalizeSlashes(fn); var justName = fn.replace(/^.*[\\\/]/, ''); // Convert to relative path diff --git a/tests/cases/fourslash/aliasMergingWithNamespace.ts b/tests/cases/fourslash/aliasMergingWithNamespace.ts new file mode 100644 index 0000000000..66ab97890c --- /dev/null +++ b/tests/cases/fourslash/aliasMergingWithNamespace.ts @@ -0,0 +1,9 @@ +/// + +////namespace bar { } +////import bar = bar/**/; + +goTo.marker(); +verify.quickInfoIs( +`namespace bar +import bar = bar`); \ No newline at end of file From 26f73d4dc89191fdc317f9e359a5035761413495 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Thu, 14 May 2015 13:20:09 -0700 Subject: [PATCH 2/2] Add a comment in getTypeOfAlias --- src/compiler/checker.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cb5bcbf0b7..7a4ba23ca2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2415,6 +2415,12 @@ module ts { let links = getSymbolLinks(symbol); if (!links.type) { let targetSymbol = resolveAlias(symbol); + + // It only makes sense to get the type of a value symbol. If the result of resolving + // the alias is not a value, then it has no type. To get the type associated with a + // type symbol, call getDeclaredTypeOfSymbol. + // This check is important because without it, a call to getTypeOfSymbol could end + // up recursively calling getTypeOfAlias, causing a stack overflow. links.type = targetSymbol.flags & SymbolFlags.Value ? getTypeOfSymbol(targetSymbol) : unknownType;