From 81763543f32c8b922d7d466d9f71240cf0f276ba Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 14 Oct 2015 12:00:43 -0700 Subject: [PATCH] Fix the duplicate function implementation error that depended on order of files --- src/compiler/checker.ts | 9 ++++++++- .../jsFileCompilationDuplicateFunctionImplementation.ts | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2127bf4587..838172345c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10770,6 +10770,7 @@ namespace ts { let symbol = getSymbolOfNode(node); let firstDeclaration = getDeclarationOfKind(symbol, node.kind); + // Only type check the symbol once if (node === firstDeclaration) { checkFunctionOrConstructorSymbol(symbol); @@ -11782,7 +11783,13 @@ namespace ts { let symbol = getSymbolOfNode(node); let localSymbol = node.localSymbol || symbol; - let firstDeclaration = getDeclarationOfKind(localSymbol, node.kind); + let firstDeclaration = forEach(symbol.declarations, declaration => { + // Get first non javascript function declaration + if (declaration.kind === node.kind && !isJavaScript(getSourceFile(declaration).fileName)) { + return declaration; + } + }); + // Only type check the symbol once if (node === firstDeclaration) { checkFunctionOrConstructorSymbol(localSymbol); diff --git a/tests/cases/fourslash/jsFileCompilationDuplicateFunctionImplementation.ts b/tests/cases/fourslash/jsFileCompilationDuplicateFunctionImplementation.ts index f9cc1f9b63..cbc83bb9c4 100644 --- a/tests/cases/fourslash/jsFileCompilationDuplicateFunctionImplementation.ts +++ b/tests/cases/fourslash/jsFileCompilationDuplicateFunctionImplementation.ts @@ -11,10 +11,14 @@ // @emitThisFile: true ////function foo() { return 30; }/*2*/ +goTo.marker("1"); +verify.getSemanticDiagnostics('[]'); goTo.marker("2"); -verify.getSemanticDiagnostics("[]"); +verify.getSemanticDiagnostics('[\n {\n "message": "Duplicate function implementation.",\n "start": 9,\n "length": 3,\n "category": "error",\n "code": 2393\n }\n]'); verify.verifyGetEmitOutputContentsForCurrentFile([ { fileName: "out.js", content: "function foo() { return 10; }\r\nfunction foo() { return 30; }\r\n" }, { fileName: "out.d.ts", content: "" }]); goTo.marker("2"); -verify.getSemanticDiagnostics('[\n {\n "message": "Duplicate function implementation.",\n "start": 9,\n "length": 3,\n "category": "error",\n "code": 2393\n }\n]'); \ No newline at end of file +verify.getSemanticDiagnostics('[\n {\n "message": "Duplicate function implementation.",\n "start": 9,\n "length": 3,\n "category": "error",\n "code": 2393\n }\n]'); +goTo.marker("1"); +verify.getSemanticDiagnostics('[]'); \ No newline at end of file