Skip to content

Commit 7f5a89a

Browse files
committed
Disallow * token on overload signatures
1 parent d52c224 commit 7f5a89a

20 files changed

+213
-0
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12553,6 +12553,9 @@ module ts {
1255312553
if (isInAmbientContext(node)) {
1255412554
return grammarErrorOnNode(node.asteriskToken, Diagnostics.Generators_are_not_allowed_in_an_ambient_context);
1255512555
}
12556+
if (!node.body) {
12557+
return grammarErrorOnNode(node.asteriskToken, Diagnostics.An_overload_signature_cannot_be_declared_as_a_generator);
12558+
}
1255612559
if (languageVersion < ScriptTarget.ES6) {
1255712560
return grammarErrorOnNode(node.asteriskToken, Diagnostics.Generators_are_only_available_when_targeting_ECMAScript_6_or_higher);
1255812561
}

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ module ts {
176176
Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1218, category: DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." },
177177
Generators_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 1219, category: DiagnosticCategory.Error, key: "Generators are only available when targeting ECMAScript 6 or higher." },
178178
Generators_are_not_allowed_in_an_ambient_context: { code: 1220, category: DiagnosticCategory.Error, key: "Generators are not allowed in an ambient context." },
179+
An_overload_signature_cannot_be_declared_as_a_generator: { code: 1221, category: DiagnosticCategory.Error, key: "An overload signature cannot be declared as a generator." },
179180
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
180181
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
181182
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,10 @@
691691
"category": "Error",
692692
"code": 1220
693693
},
694+
"An overload signature cannot be declared as a generator.": {
695+
"category": "Error",
696+
"code": 1221
697+
},
694698

695699

696700
"Duplicate identifier '{0}'.": {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tests/cases/conformance/es6/yieldExpressions/generatorOverloads1.ts(2,13): error TS1220: An overload signature cannot be declared as a generator.
2+
tests/cases/conformance/es6/yieldExpressions/generatorOverloads1.ts(3,13): error TS1220: An overload signature cannot be declared as a generator.
3+
4+
5+
==== tests/cases/conformance/es6/yieldExpressions/generatorOverloads1.ts (2 errors) ====
6+
module M {
7+
function* f(s: string): Iterable<any>;
8+
~
9+
!!! error TS1220: An overload signature cannot be declared as a generator.
10+
function* f(s: number): Iterable<any>;
11+
~
12+
!!! error TS1220: An overload signature cannot be declared as a generator.
13+
function* f(s: any): Iterable<any> { }
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [generatorOverloads1.ts]
2+
module M {
3+
function* f(s: string): Iterable<any>;
4+
function* f(s: number): Iterable<any>;
5+
function* f(s: any): Iterable<any> { }
6+
}
7+
8+
//// [generatorOverloads1.js]
9+
var M;
10+
(function (M) {
11+
function* f(s) { }
12+
})(M || (M = {}));
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts(2,13): error TS1219: Generators are not allowed in an ambient context.
2+
tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts(3,13): error TS1219: Generators are not allowed in an ambient context.
3+
tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts(4,13): error TS1219: Generators are not allowed in an ambient context.
4+
5+
6+
==== tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts (3 errors) ====
7+
declare module M {
8+
function* f(s: string): Iterable<any>;
9+
~
10+
!!! error TS1219: Generators are not allowed in an ambient context.
11+
function* f(s: number): Iterable<any>;
12+
~
13+
!!! error TS1219: Generators are not allowed in an ambient context.
14+
function* f(s: any): Iterable<any>;
15+
~
16+
!!! error TS1219: Generators are not allowed in an ambient context.
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [generatorOverloads2.ts]
2+
declare module M {
3+
function* f(s: string): Iterable<any>;
4+
function* f(s: number): Iterable<any>;
5+
function* f(s: any): Iterable<any>;
6+
}
7+
8+
//// [generatorOverloads2.js]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts(2,5): error TS1220: An overload signature cannot be declared as a generator.
2+
tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts(3,5): error TS1220: An overload signature cannot be declared as a generator.
3+
4+
5+
==== tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts (2 errors) ====
6+
class C {
7+
*f(s: string): Iterable<any>;
8+
~
9+
!!! error TS1220: An overload signature cannot be declared as a generator.
10+
*f(s: number): Iterable<any>;
11+
~
12+
!!! error TS1220: An overload signature cannot be declared as a generator.
13+
*f(s: any): Iterable<any> { }
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [generatorOverloads3.ts]
2+
class C {
3+
*f(s: string): Iterable<any>;
4+
*f(s: number): Iterable<any>;
5+
*f(s: any): Iterable<any> { }
6+
}
7+
8+
//// [generatorOverloads3.js]
9+
class C {
10+
*f(s) { }
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [generatorOverloads4.ts]
2+
class C {
3+
f(s: string): Iterable<any>;
4+
f(s: number): Iterable<any>;
5+
*f(s: any): Iterable<any> { }
6+
}
7+
8+
//// [generatorOverloads4.js]
9+
class C {
10+
*f(s) { }
11+
}

0 commit comments

Comments
 (0)