Skip to content

Commit 97be083

Browse files
authored
Merge pull request #9100 from Microsoft/Fix9098
Fix #9098: report missing function implementation errors for merged …
2 parents a3a0c98 + e86f183 commit 97be083

7 files changed

+428
-5
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13559,9 +13559,6 @@ namespace ts {
1355913559
}
1356013560
}
1356113561

13562-
// when checking exported function declarations across modules check only duplicate implementations
13563-
// names and consistency of modifiers are verified when we check local symbol
13564-
const isExportSymbolInsideModule = symbol.parent && symbol.parent.flags & SymbolFlags.Module;
1356513562
let duplicateFunctionDeclaration = false;
1356613563
let multipleConstructorImplementation = false;
1356713564
for (const current of declarations) {
@@ -13594,7 +13591,7 @@ namespace ts {
1359413591
duplicateFunctionDeclaration = true;
1359513592
}
1359613593
}
13597-
else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) {
13594+
else if (previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) {
1359813595
reportImplementationExpectedError(previousDeclaration);
1359913596
}
1360013597

@@ -13628,7 +13625,7 @@ namespace ts {
1362813625
}
1362913626

1363013627
// Abstract methods can't have an implementation -- in particular, they don't need one.
13631-
if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body &&
13628+
if (lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body &&
1363213629
!(lastSeenNonAmbientDeclaration.flags & NodeFlags.Abstract) && !lastSeenNonAmbientDeclaration.questionToken) {
1363313630
reportImplementationExpectedError(lastSeenNonAmbientDeclaration);
1363413631
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
tests/cases/compiler/missingFunctionImplementation.ts(3,3): error TS2391: Function implementation is missing or not immediately following the declaration.
2+
tests/cases/compiler/missingFunctionImplementation.ts(8,3): error TS2391: Function implementation is missing or not immediately following the declaration.
3+
tests/cases/compiler/missingFunctionImplementation.ts(16,3): error TS2391: Function implementation is missing or not immediately following the declaration.
4+
tests/cases/compiler/missingFunctionImplementation.ts(22,10): error TS2391: Function implementation is missing or not immediately following the declaration.
5+
tests/cases/compiler/missingFunctionImplementation.ts(28,10): error TS2391: Function implementation is missing or not immediately following the declaration.
6+
tests/cases/compiler/missingFunctionImplementation.ts(33,10): error TS2391: Function implementation is missing or not immediately following the declaration.
7+
tests/cases/compiler/missingFunctionImplementation.ts(41,10): error TS2391: Function implementation is missing or not immediately following the declaration.
8+
tests/cases/compiler/missingFunctionImplementation.ts(48,10): error TS2300: Duplicate identifier 'm'.
9+
tests/cases/compiler/missingFunctionImplementation.ts(49,10): error TS2300: Duplicate identifier 'm'.
10+
tests/cases/compiler/missingFunctionImplementation.ts(49,10): error TS2391: Function implementation is missing or not immediately following the declaration.
11+
tests/cases/compiler/missingFunctionImplementation.ts(52,19): error TS2300: Duplicate identifier 'm'.
12+
tests/cases/compiler/missingFunctionImplementation.ts(57,10): error TS2300: Duplicate identifier 'm'.
13+
tests/cases/compiler/missingFunctionImplementation.ts(60,19): error TS2300: Duplicate identifier 'm'.
14+
tests/cases/compiler/missingFunctionImplementation.ts(60,19): error TS2391: Function implementation is missing or not immediately following the declaration.
15+
tests/cases/compiler/missingFunctionImplementation.ts(65,19): error TS2391: Function implementation is missing or not immediately following the declaration.
16+
tests/cases/compiler/missingFunctionImplementation.ts(73,19): error TS2393: Duplicate function implementation.
17+
tests/cases/compiler/missingFunctionImplementation.ts(74,19): error TS2393: Duplicate function implementation.
18+
tests/cases/compiler/missingFunctionImplementation.ts(75,19): error TS2393: Duplicate function implementation.
19+
tests/cases/compiler/missingFunctionImplementation.ts(78,19): error TS2393: Duplicate function implementation.
20+
21+
22+
==== tests/cases/compiler/missingFunctionImplementation.ts (19 errors) ====
23+
24+
export class C1 {
25+
m(): void;
26+
~
27+
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
28+
}
29+
30+
// merged with a namespace
31+
export class C2 {
32+
m(): void;
33+
~
34+
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
35+
}
36+
export namespace C2 { }
37+
38+
39+
// merged with a namespace, multiple overloads
40+
class C3 {
41+
m(a, b);
42+
m(a);
43+
~
44+
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
45+
}
46+
namespace C3 { }
47+
48+
// static methods, multiple overloads
49+
class C4 {
50+
static m(a): void;
51+
~
52+
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
53+
}
54+
55+
// static methods, multiple overloads
56+
class C5 {
57+
static m(a): void;
58+
static m(): void;
59+
~
60+
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
61+
}
62+
63+
// merged with namespace, static methods
64+
class C6 {
65+
static m(): void;
66+
~
67+
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
68+
}
69+
namespace C6 {
70+
}
71+
72+
// merged with namespace, static methods, multiple overloads
73+
class C7 {
74+
static m(a): void;
75+
static m(): void;
76+
~
77+
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
78+
}
79+
namespace C7 {
80+
}
81+
82+
// merged with namespace, static methods, duplicate declarations
83+
class C8 {
84+
static m(a): void;
85+
~
86+
!!! error TS2300: Duplicate identifier 'm'.
87+
static m(a, b): void;
88+
~
89+
!!! error TS2300: Duplicate identifier 'm'.
90+
~
91+
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
92+
}
93+
namespace C8 {
94+
export function m(a?, b?): void { }
95+
~
96+
!!! error TS2300: Duplicate identifier 'm'.
97+
}
98+
99+
// merged with namespace, static methods, duplicate declarations
100+
class C9 {
101+
static m(a): void { }
102+
~
103+
!!! error TS2300: Duplicate identifier 'm'.
104+
}
105+
namespace C9 {
106+
export function m(a): void;
107+
~
108+
!!! error TS2300: Duplicate identifier 'm'.
109+
~
110+
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
111+
}
112+
113+
// merged namespaces
114+
namespace N10 {
115+
export function m(a): void;
116+
~
117+
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
118+
}
119+
namespace N10 {
120+
export function m(a): void { }
121+
}
122+
123+
// merged namespaces, duplicate defintions
124+
namespace N12 {
125+
export function m(a): void;
126+
~
127+
!!! error TS2393: Duplicate function implementation.
128+
export function m(): void;
129+
~
130+
!!! error TS2393: Duplicate function implementation.
131+
export function m(a?): void { }
132+
~
133+
!!! error TS2393: Duplicate function implementation.
134+
}
135+
namespace N12 {
136+
export function m(a): void { }
137+
~
138+
!!! error TS2393: Duplicate function implementation.
139+
}
140+
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
//// [missingFunctionImplementation.ts]
2+
3+
export class C1 {
4+
m(): void;
5+
}
6+
7+
// merged with a namespace
8+
export class C2 {
9+
m(): void;
10+
}
11+
export namespace C2 { }
12+
13+
14+
// merged with a namespace, multiple overloads
15+
class C3 {
16+
m(a, b);
17+
m(a);
18+
}
19+
namespace C3 { }
20+
21+
// static methods, multiple overloads
22+
class C4 {
23+
static m(a): void;
24+
}
25+
26+
// static methods, multiple overloads
27+
class C5 {
28+
static m(a): void;
29+
static m(): void;
30+
}
31+
32+
// merged with namespace, static methods
33+
class C6 {
34+
static m(): void;
35+
}
36+
namespace C6 {
37+
}
38+
39+
// merged with namespace, static methods, multiple overloads
40+
class C7 {
41+
static m(a): void;
42+
static m(): void;
43+
}
44+
namespace C7 {
45+
}
46+
47+
// merged with namespace, static methods, duplicate declarations
48+
class C8 {
49+
static m(a): void;
50+
static m(a, b): void;
51+
}
52+
namespace C8 {
53+
export function m(a?, b?): void { }
54+
}
55+
56+
// merged with namespace, static methods, duplicate declarations
57+
class C9 {
58+
static m(a): void { }
59+
}
60+
namespace C9 {
61+
export function m(a): void;
62+
}
63+
64+
// merged namespaces
65+
namespace N10 {
66+
export function m(a): void;
67+
}
68+
namespace N10 {
69+
export function m(a): void { }
70+
}
71+
72+
// merged namespaces, duplicate defintions
73+
namespace N12 {
74+
export function m(a): void;
75+
export function m(): void;
76+
export function m(a?): void { }
77+
}
78+
namespace N12 {
79+
export function m(a): void { }
80+
}
81+
82+
83+
//// [missingFunctionImplementation.js]
84+
"use strict";
85+
var C1 = (function () {
86+
function C1() {
87+
}
88+
return C1;
89+
}());
90+
exports.C1 = C1;
91+
// merged with a namespace
92+
var C2 = (function () {
93+
function C2() {
94+
}
95+
return C2;
96+
}());
97+
exports.C2 = C2;
98+
// merged with a namespace, multiple overloads
99+
var C3 = (function () {
100+
function C3() {
101+
}
102+
return C3;
103+
}());
104+
// static methods, multiple overloads
105+
var C4 = (function () {
106+
function C4() {
107+
}
108+
return C4;
109+
}());
110+
// static methods, multiple overloads
111+
var C5 = (function () {
112+
function C5() {
113+
}
114+
return C5;
115+
}());
116+
// merged with namespace, static methods
117+
var C6 = (function () {
118+
function C6() {
119+
}
120+
return C6;
121+
}());
122+
// merged with namespace, static methods, multiple overloads
123+
var C7 = (function () {
124+
function C7() {
125+
}
126+
return C7;
127+
}());
128+
// merged with namespace, static methods, duplicate declarations
129+
var C8 = (function () {
130+
function C8() {
131+
}
132+
return C8;
133+
}());
134+
var C8;
135+
(function (C8) {
136+
function m(a, b) { }
137+
C8.m = m;
138+
})(C8 || (C8 = {}));
139+
// merged with namespace, static methods, duplicate declarations
140+
var C9 = (function () {
141+
function C9() {
142+
}
143+
C9.m = function (a) { };
144+
return C9;
145+
}());
146+
var C9;
147+
(function (C9) {
148+
})(C9 || (C9 = {}));
149+
// merged namespaces
150+
var N10;
151+
(function (N10) {
152+
})(N10 || (N10 = {}));
153+
var N10;
154+
(function (N10) {
155+
function m(a) { }
156+
N10.m = m;
157+
})(N10 || (N10 = {}));
158+
// merged namespaces, duplicate defintions
159+
var N12;
160+
(function (N12) {
161+
function m(a) { }
162+
N12.m = m;
163+
})(N12 || (N12 = {}));
164+
var N12;
165+
(function (N12) {
166+
function m(a) { }
167+
N12.m = m;
168+
})(N12 || (N12 = {}));
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
tests/cases/compiler/missingFunctionImplementation2_a.ts(3,19): error TS2384: Overload signatures must all be ambient or non-ambient.
2+
tests/cases/compiler/missingFunctionImplementation2_b.ts(1,17): error TS2391: Function implementation is missing or not immediately following the declaration.
3+
4+
5+
==== tests/cases/compiler/missingFunctionImplementation2_a.ts (1 errors) ====
6+
export {};
7+
declare module "./missingFunctionImplementation2_b.ts" {
8+
export function f(a, b): void;
9+
~
10+
!!! error TS2384: Overload signatures must all be ambient or non-ambient.
11+
}
12+
13+
==== tests/cases/compiler/missingFunctionImplementation2_b.ts (1 errors) ====
14+
export function f(a?, b?);
15+
~
16+
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//// [tests/cases/compiler/missingFunctionImplementation2.ts] ////
2+
3+
//// [missingFunctionImplementation2_a.ts]
4+
export {};
5+
declare module "./missingFunctionImplementation2_b.ts" {
6+
export function f(a, b): void;
7+
}
8+
9+
//// [missingFunctionImplementation2_b.ts]
10+
export function f(a?, b?);
11+
12+
//// [missingFunctionImplementation2_a.js]
13+
"use strict";
14+
//// [missingFunctionImplementation2_b.js]
15+
"use strict";

0 commit comments

Comments
 (0)