Skip to content

Fix #9098: report missing function implementation errors for merged … #9100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand Down
140 changes: 140 additions & 0 deletions tests/baselines/reference/missingFunctionImplementation.errors.txt
Original file line number Diff line number Diff line change
@@ -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.
}

168 changes: 168 additions & 0 deletions tests/baselines/reference/missingFunctionImplementation.js
Original file line number Diff line number Diff line change
@@ -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 = {}));
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 15 additions & 0 deletions tests/baselines/reference/missingFunctionImplementation2.js
Original file line number Diff line number Diff line change
@@ -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";
Loading