diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 28082914256a3..f35a53ce368e4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13552,9 +13552,6 @@ namespace ts { } } - // when checking exported function declarations across modules check only duplicate implementations - // names and consistency of modifiers are verified when we check local symbol - const isExportSymbolInsideModule = symbol.parent && symbol.parent.flags & SymbolFlags.Module; let duplicateFunctionDeclaration = false; let multipleConstructorImplementation = false; for (const current of declarations) { @@ -13587,7 +13584,7 @@ namespace ts { duplicateFunctionDeclaration = true; } } - else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) { + else if (previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) { reportImplementationExpectedError(previousDeclaration); } @@ -13621,7 +13618,7 @@ namespace ts { } // Abstract methods can't have an implementation -- in particular, they don't need one. - if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body && + if (lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body && !(lastSeenNonAmbientDeclaration.flags & NodeFlags.Abstract) && !lastSeenNonAmbientDeclaration.questionToken) { reportImplementationExpectedError(lastSeenNonAmbientDeclaration); } diff --git a/tests/baselines/reference/missingFunctionImplementation.errors.txt b/tests/baselines/reference/missingFunctionImplementation.errors.txt new file mode 100644 index 0000000000000..4cf58d97d4909 --- /dev/null +++ b/tests/baselines/reference/missingFunctionImplementation.errors.txt @@ -0,0 +1,140 @@ +tests/cases/compiler/missingFunctionImplementation.ts(3,3): error TS2391: Function implementation is missing or not immediately following the declaration. +tests/cases/compiler/missingFunctionImplementation.ts(8,3): error TS2391: Function implementation is missing or not immediately following the declaration. +tests/cases/compiler/missingFunctionImplementation.ts(16,3): error TS2391: Function implementation is missing or not immediately following the declaration. +tests/cases/compiler/missingFunctionImplementation.ts(22,10): error TS2391: Function implementation is missing or not immediately following the declaration. +tests/cases/compiler/missingFunctionImplementation.ts(28,10): error TS2391: Function implementation is missing or not immediately following the declaration. +tests/cases/compiler/missingFunctionImplementation.ts(33,10): error TS2391: Function implementation is missing or not immediately following the declaration. +tests/cases/compiler/missingFunctionImplementation.ts(41,10): error TS2391: Function implementation is missing or not immediately following the declaration. +tests/cases/compiler/missingFunctionImplementation.ts(48,10): error TS2300: Duplicate identifier 'm'. +tests/cases/compiler/missingFunctionImplementation.ts(49,10): error TS2300: Duplicate identifier 'm'. +tests/cases/compiler/missingFunctionImplementation.ts(49,10): error TS2391: Function implementation is missing or not immediately following the declaration. +tests/cases/compiler/missingFunctionImplementation.ts(52,19): error TS2300: Duplicate identifier 'm'. +tests/cases/compiler/missingFunctionImplementation.ts(57,10): error TS2300: Duplicate identifier 'm'. +tests/cases/compiler/missingFunctionImplementation.ts(60,19): error TS2300: Duplicate identifier 'm'. +tests/cases/compiler/missingFunctionImplementation.ts(60,19): error TS2391: Function implementation is missing or not immediately following the declaration. +tests/cases/compiler/missingFunctionImplementation.ts(65,19): error TS2391: Function implementation is missing or not immediately following the declaration. +tests/cases/compiler/missingFunctionImplementation.ts(73,19): error TS2393: Duplicate function implementation. +tests/cases/compiler/missingFunctionImplementation.ts(74,19): error TS2393: Duplicate function implementation. +tests/cases/compiler/missingFunctionImplementation.ts(75,19): error TS2393: Duplicate function implementation. +tests/cases/compiler/missingFunctionImplementation.ts(78,19): error TS2393: Duplicate function implementation. + + +==== tests/cases/compiler/missingFunctionImplementation.ts (19 errors) ==== + + export class C1 { + m(): void; + ~ +!!! error TS2391: Function implementation is missing or not immediately following the declaration. + } + + // merged with a namespace + export class C2 { + m(): void; + ~ +!!! error TS2391: Function implementation is missing or not immediately following the declaration. + } + export namespace C2 { } + + + // merged with a namespace, multiple overloads + class C3 { + m(a, b); + m(a); + ~ +!!! error TS2391: Function implementation is missing or not immediately following the declaration. + } + namespace C3 { } + + // static methods, multiple overloads + class C4 { + static m(a): void; + ~ +!!! error TS2391: Function implementation is missing or not immediately following the declaration. + } + + // static methods, multiple overloads + class C5 { + static m(a): void; + static m(): void; + ~ +!!! error TS2391: Function implementation is missing or not immediately following the declaration. + } + + // merged with namespace, static methods + class C6 { + static m(): void; + ~ +!!! error TS2391: Function implementation is missing or not immediately following the declaration. + } + namespace C6 { + } + + // merged with namespace, static methods, multiple overloads + class C7 { + static m(a): void; + static m(): void; + ~ +!!! error TS2391: Function implementation is missing or not immediately following the declaration. + } + namespace C7 { + } + + // merged with namespace, static methods, duplicate declarations + class C8 { + static m(a): void; + ~ +!!! error TS2300: Duplicate identifier 'm'. + static m(a, b): void; + ~ +!!! error TS2300: Duplicate identifier 'm'. + ~ +!!! error TS2391: Function implementation is missing or not immediately following the declaration. + } + namespace C8 { + export function m(a?, b?): void { } + ~ +!!! error TS2300: Duplicate identifier 'm'. + } + + // merged with namespace, static methods, duplicate declarations + class C9 { + static m(a): void { } + ~ +!!! error TS2300: Duplicate identifier 'm'. + } + namespace C9 { + export function m(a): void; + ~ +!!! error TS2300: Duplicate identifier 'm'. + ~ +!!! error TS2391: Function implementation is missing or not immediately following the declaration. + } + + // merged namespaces + namespace N10 { + export function m(a): void; + ~ +!!! error TS2391: Function implementation is missing or not immediately following the declaration. + } + namespace N10 { + export function m(a): void { } + } + + // merged namespaces, duplicate defintions + namespace N12 { + export function m(a): void; + ~ +!!! error TS2393: Duplicate function implementation. + export function m(): void; + ~ +!!! error TS2393: Duplicate function implementation. + export function m(a?): void { } + ~ +!!! error TS2393: Duplicate function implementation. + } + namespace N12 { + export function m(a): void { } + ~ +!!! error TS2393: Duplicate function implementation. + } + \ No newline at end of file diff --git a/tests/baselines/reference/missingFunctionImplementation.js b/tests/baselines/reference/missingFunctionImplementation.js new file mode 100644 index 0000000000000..a452c8080b75d --- /dev/null +++ b/tests/baselines/reference/missingFunctionImplementation.js @@ -0,0 +1,168 @@ +//// [missingFunctionImplementation.ts] + +export class C1 { + m(): void; +} + +// merged with a namespace +export class C2 { + m(): void; +} +export namespace C2 { } + + +// merged with a namespace, multiple overloads +class C3 { + m(a, b); + m(a); +} +namespace C3 { } + +// static methods, multiple overloads +class C4 { + static m(a): void; +} + +// static methods, multiple overloads +class C5 { + static m(a): void; + static m(): void; +} + +// merged with namespace, static methods +class C6 { + static m(): void; +} +namespace C6 { +} + +// merged with namespace, static methods, multiple overloads +class C7 { + static m(a): void; + static m(): void; +} +namespace C7 { +} + +// merged with namespace, static methods, duplicate declarations +class C8 { + static m(a): void; + static m(a, b): void; +} +namespace C8 { + export function m(a?, b?): void { } +} + +// merged with namespace, static methods, duplicate declarations +class C9 { + static m(a): void { } +} +namespace C9 { + export function m(a): void; +} + +// merged namespaces +namespace N10 { + export function m(a): void; +} +namespace N10 { + export function m(a): void { } +} + +// merged namespaces, duplicate defintions +namespace N12 { + export function m(a): void; + export function m(): void; + export function m(a?): void { } +} +namespace N12 { + export function m(a): void { } +} + + +//// [missingFunctionImplementation.js] +"use strict"; +var C1 = (function () { + function C1() { + } + return C1; +}()); +exports.C1 = C1; +// merged with a namespace +var C2 = (function () { + function C2() { + } + return C2; +}()); +exports.C2 = C2; +// merged with a namespace, multiple overloads +var C3 = (function () { + function C3() { + } + return C3; +}()); +// static methods, multiple overloads +var C4 = (function () { + function C4() { + } + return C4; +}()); +// static methods, multiple overloads +var C5 = (function () { + function C5() { + } + return C5; +}()); +// merged with namespace, static methods +var C6 = (function () { + function C6() { + } + return C6; +}()); +// merged with namespace, static methods, multiple overloads +var C7 = (function () { + function C7() { + } + return C7; +}()); +// merged with namespace, static methods, duplicate declarations +var C8 = (function () { + function C8() { + } + return C8; +}()); +var C8; +(function (C8) { + function m(a, b) { } + C8.m = m; +})(C8 || (C8 = {})); +// merged with namespace, static methods, duplicate declarations +var C9 = (function () { + function C9() { + } + C9.m = function (a) { }; + return C9; +}()); +var C9; +(function (C9) { +})(C9 || (C9 = {})); +// merged namespaces +var N10; +(function (N10) { +})(N10 || (N10 = {})); +var N10; +(function (N10) { + function m(a) { } + N10.m = m; +})(N10 || (N10 = {})); +// merged namespaces, duplicate defintions +var N12; +(function (N12) { + function m(a) { } + N12.m = m; +})(N12 || (N12 = {})); +var N12; +(function (N12) { + function m(a) { } + N12.m = m; +})(N12 || (N12 = {})); diff --git a/tests/baselines/reference/missingFunctionImplementation2.errors.txt b/tests/baselines/reference/missingFunctionImplementation2.errors.txt new file mode 100644 index 0000000000000..a695482e1fba3 --- /dev/null +++ b/tests/baselines/reference/missingFunctionImplementation2.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/missingFunctionImplementation2_a.ts(3,19): error TS2384: Overload signatures must all be ambient or non-ambient. +tests/cases/compiler/missingFunctionImplementation2_b.ts(1,17): error TS2391: Function implementation is missing or not immediately following the declaration. + + +==== tests/cases/compiler/missingFunctionImplementation2_a.ts (1 errors) ==== + export {}; + declare module "./missingFunctionImplementation2_b.ts" { + export function f(a, b): void; + ~ +!!! error TS2384: Overload signatures must all be ambient or non-ambient. + } + +==== tests/cases/compiler/missingFunctionImplementation2_b.ts (1 errors) ==== + export function f(a?, b?); + ~ +!!! error TS2391: Function implementation is missing or not immediately following the declaration. \ No newline at end of file diff --git a/tests/baselines/reference/missingFunctionImplementation2.js b/tests/baselines/reference/missingFunctionImplementation2.js new file mode 100644 index 0000000000000..104b6dd9443d6 --- /dev/null +++ b/tests/baselines/reference/missingFunctionImplementation2.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/missingFunctionImplementation2.ts] //// + +//// [missingFunctionImplementation2_a.ts] +export {}; +declare module "./missingFunctionImplementation2_b.ts" { + export function f(a, b): void; +} + +//// [missingFunctionImplementation2_b.ts] +export function f(a?, b?); + +//// [missingFunctionImplementation2_a.js] +"use strict"; +//// [missingFunctionImplementation2_b.js] +"use strict"; diff --git a/tests/cases/compiler/missingFunctionImplementation.ts b/tests/cases/compiler/missingFunctionImplementation.ts new file mode 100644 index 0000000000000..e261db3a6670e --- /dev/null +++ b/tests/cases/compiler/missingFunctionImplementation.ts @@ -0,0 +1,79 @@ + +export class C1 { + m(): void; +} + +// merged with a namespace +export class C2 { + m(): void; +} +export namespace C2 { } + + +// merged with a namespace, multiple overloads +class C3 { + m(a, b); + m(a); +} +namespace C3 { } + +// static methods, multiple overloads +class C4 { + static m(a): void; +} + +// static methods, multiple overloads +class C5 { + static m(a): void; + static m(): void; +} + +// merged with namespace, static methods +class C6 { + static m(): void; +} +namespace C6 { +} + +// merged with namespace, static methods, multiple overloads +class C7 { + static m(a): void; + static m(): void; +} +namespace C7 { +} + +// merged with namespace, static methods, duplicate declarations +class C8 { + static m(a): void; + static m(a, b): void; +} +namespace C8 { + export function m(a?, b?): void { } +} + +// merged with namespace, static methods, duplicate declarations +class C9 { + static m(a): void { } +} +namespace C9 { + export function m(a): void; +} + +// merged namespaces +namespace N10 { + export function m(a): void; +} +namespace N10 { + export function m(a): void { } +} + +// merged namespaces, duplicate defintions +namespace N12 { + export function m(a): void; + export function m(): void; + export function m(a?): void { } +} +namespace N12 { + export function m(a): void { } +} diff --git a/tests/cases/compiler/missingFunctionImplementation2.ts b/tests/cases/compiler/missingFunctionImplementation2.ts new file mode 100644 index 0000000000000..25909b6add4c2 --- /dev/null +++ b/tests/cases/compiler/missingFunctionImplementation2.ts @@ -0,0 +1,8 @@ +// @Filename: missingFunctionImplementation2_a.ts +export {}; +declare module "./missingFunctionImplementation2_b.ts" { + export function f(a, b): void; +} + +// @Filename: missingFunctionImplementation2_b.ts +export function f(a?, b?); \ No newline at end of file