Disallow * token on overload signatures

This commit is contained in:
Jason Freeman 2015-04-23 13:25:41 -07:00
parent d52c224697
commit 7f5a89ae5e
20 changed files with 213 additions and 0 deletions

View File

@ -12553,6 +12553,9 @@ module ts {
if (isInAmbientContext(node)) {
return grammarErrorOnNode(node.asteriskToken, Diagnostics.Generators_are_not_allowed_in_an_ambient_context);
}
if (!node.body) {
return grammarErrorOnNode(node.asteriskToken, Diagnostics.An_overload_signature_cannot_be_declared_as_a_generator);
}
if (languageVersion < ScriptTarget.ES6) {
return grammarErrorOnNode(node.asteriskToken, Diagnostics.Generators_are_only_available_when_targeting_ECMAScript_6_or_higher);
}

View File

@ -176,6 +176,7 @@ module ts {
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'." },
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." },
Generators_are_not_allowed_in_an_ambient_context: { code: 1220, category: DiagnosticCategory.Error, key: "Generators are not allowed in an ambient context." },
An_overload_signature_cannot_be_declared_as_a_generator: { code: 1221, category: DiagnosticCategory.Error, key: "An overload signature cannot be declared as a generator." },
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
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." },
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },

View File

@ -691,6 +691,10 @@
"category": "Error",
"code": 1220
},
"An overload signature cannot be declared as a generator.": {
"category": "Error",
"code": 1221
},
"Duplicate identifier '{0}'.": {

View File

@ -0,0 +1,14 @@
tests/cases/conformance/es6/yieldExpressions/generatorOverloads1.ts(2,13): error TS1220: An overload signature cannot be declared as a generator.
tests/cases/conformance/es6/yieldExpressions/generatorOverloads1.ts(3,13): error TS1220: An overload signature cannot be declared as a generator.
==== tests/cases/conformance/es6/yieldExpressions/generatorOverloads1.ts (2 errors) ====
module M {
function* f(s: string): Iterable<any>;
~
!!! error TS1220: An overload signature cannot be declared as a generator.
function* f(s: number): Iterable<any>;
~
!!! error TS1220: An overload signature cannot be declared as a generator.
function* f(s: any): Iterable<any> { }
}

View File

@ -0,0 +1,12 @@
//// [generatorOverloads1.ts]
module M {
function* f(s: string): Iterable<any>;
function* f(s: number): Iterable<any>;
function* f(s: any): Iterable<any> { }
}
//// [generatorOverloads1.js]
var M;
(function (M) {
function* f(s) { }
})(M || (M = {}));

View File

@ -0,0 +1,17 @@
tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts(2,13): error TS1219: Generators are not allowed in an ambient context.
tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts(3,13): error TS1219: Generators are not allowed in an ambient context.
tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts(4,13): error TS1219: Generators are not allowed in an ambient context.
==== tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts (3 errors) ====
declare module M {
function* f(s: string): Iterable<any>;
~
!!! error TS1219: Generators are not allowed in an ambient context.
function* f(s: number): Iterable<any>;
~
!!! error TS1219: Generators are not allowed in an ambient context.
function* f(s: any): Iterable<any>;
~
!!! error TS1219: Generators are not allowed in an ambient context.
}

View File

@ -0,0 +1,8 @@
//// [generatorOverloads2.ts]
declare module M {
function* f(s: string): Iterable<any>;
function* f(s: number): Iterable<any>;
function* f(s: any): Iterable<any>;
}
//// [generatorOverloads2.js]

View File

@ -0,0 +1,14 @@
tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts(2,5): error TS1220: An overload signature cannot be declared as a generator.
tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts(3,5): error TS1220: An overload signature cannot be declared as a generator.
==== tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts (2 errors) ====
class C {
*f(s: string): Iterable<any>;
~
!!! error TS1220: An overload signature cannot be declared as a generator.
*f(s: number): Iterable<any>;
~
!!! error TS1220: An overload signature cannot be declared as a generator.
*f(s: any): Iterable<any> { }
}

View File

@ -0,0 +1,11 @@
//// [generatorOverloads3.ts]
class C {
*f(s: string): Iterable<any>;
*f(s: number): Iterable<any>;
*f(s: any): Iterable<any> { }
}
//// [generatorOverloads3.js]
class C {
*f(s) { }
}

View File

@ -0,0 +1,11 @@
//// [generatorOverloads4.ts]
class C {
f(s: string): Iterable<any>;
f(s: number): Iterable<any>;
*f(s: any): Iterable<any> { }
}
//// [generatorOverloads4.js]
class C {
*f(s) { }
}

View File

@ -0,0 +1,19 @@
=== tests/cases/conformance/es6/yieldExpressions/generatorOverloads4.ts ===
class C {
>C : Symbol(C, Decl(generatorOverloads4.ts, 0, 0))
f(s: string): Iterable<any>;
>f : Symbol(f, Decl(generatorOverloads4.ts, 0, 9), Decl(generatorOverloads4.ts, 1, 32), Decl(generatorOverloads4.ts, 2, 32))
>s : Symbol(s, Decl(generatorOverloads4.ts, 1, 6))
>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1633, 1))
f(s: number): Iterable<any>;
>f : Symbol(f, Decl(generatorOverloads4.ts, 0, 9), Decl(generatorOverloads4.ts, 1, 32), Decl(generatorOverloads4.ts, 2, 32))
>s : Symbol(s, Decl(generatorOverloads4.ts, 2, 6))
>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1633, 1))
*f(s: any): Iterable<any> { }
>f : Symbol(f, Decl(generatorOverloads4.ts, 0, 9), Decl(generatorOverloads4.ts, 1, 32), Decl(generatorOverloads4.ts, 2, 32))
>s : Symbol(s, Decl(generatorOverloads4.ts, 3, 7))
>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1633, 1))
}

View File

@ -0,0 +1,19 @@
=== tests/cases/conformance/es6/yieldExpressions/generatorOverloads4.ts ===
class C {
>C : C
f(s: string): Iterable<any>;
>f : { (s: string): Iterable<any>; (s: number): Iterable<any>; }
>s : string
>Iterable : Iterable<T>
f(s: number): Iterable<any>;
>f : { (s: string): Iterable<any>; (s: number): Iterable<any>; }
>s : number
>Iterable : Iterable<T>
*f(s: any): Iterable<any> { }
>f : { (s: string): Iterable<any>; (s: number): Iterable<any>; }
>s : any
>Iterable : Iterable<T>
}

View File

@ -0,0 +1,12 @@
//// [generatorOverloads5.ts]
module M {
function f(s: string): Iterable<any>;
function f(s: number): Iterable<any>;
function* f(s: any): Iterable<any> { }
}
//// [generatorOverloads5.js]
var M;
(function (M) {
function* f(s) { }
})(M || (M = {}));

View File

@ -0,0 +1,19 @@
=== tests/cases/conformance/es6/yieldExpressions/generatorOverloads5.ts ===
module M {
>M : Symbol(M, Decl(generatorOverloads5.ts, 0, 0))
function f(s: string): Iterable<any>;
>f : Symbol(f, Decl(generatorOverloads5.ts, 0, 10), Decl(generatorOverloads5.ts, 1, 41), Decl(generatorOverloads5.ts, 2, 41))
>s : Symbol(s, Decl(generatorOverloads5.ts, 1, 15))
>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1633, 1))
function f(s: number): Iterable<any>;
>f : Symbol(f, Decl(generatorOverloads5.ts, 0, 10), Decl(generatorOverloads5.ts, 1, 41), Decl(generatorOverloads5.ts, 2, 41))
>s : Symbol(s, Decl(generatorOverloads5.ts, 2, 15))
>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1633, 1))
function* f(s: any): Iterable<any> { }
>f : Symbol(f, Decl(generatorOverloads5.ts, 0, 10), Decl(generatorOverloads5.ts, 1, 41), Decl(generatorOverloads5.ts, 2, 41))
>s : Symbol(s, Decl(generatorOverloads5.ts, 3, 16))
>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1633, 1))
}

View File

@ -0,0 +1,19 @@
=== tests/cases/conformance/es6/yieldExpressions/generatorOverloads5.ts ===
module M {
>M : typeof M
function f(s: string): Iterable<any>;
>f : { (s: string): Iterable<any>; (s: number): Iterable<any>; }
>s : string
>Iterable : Iterable<T>
function f(s: number): Iterable<any>;
>f : { (s: string): Iterable<any>; (s: number): Iterable<any>; }
>s : number
>Iterable : Iterable<T>
function* f(s: any): Iterable<any> { }
>f : { (s: string): Iterable<any>; (s: number): Iterable<any>; }
>s : any
>Iterable : Iterable<T>
}

View File

@ -0,0 +1,6 @@
//@target: ES6
module M {
function* f(s: string): Iterable<any>;
function* f(s: number): Iterable<any>;
function* f(s: any): Iterable<any> { }
}

View File

@ -0,0 +1,6 @@
//@target: ES6
declare module M {
function* f(s: string): Iterable<any>;
function* f(s: number): Iterable<any>;
function* f(s: any): Iterable<any>;
}

View File

@ -0,0 +1,6 @@
//@target: ES6
class C {
*f(s: string): Iterable<any>;
*f(s: number): Iterable<any>;
*f(s: any): Iterable<any> { }
}

View File

@ -0,0 +1,6 @@
//@target: ES6
class C {
f(s: string): Iterable<any>;
f(s: number): Iterable<any>;
*f(s: any): Iterable<any> { }
}

View File

@ -0,0 +1,6 @@
//@target: ES6
module M {
function f(s: string): Iterable<any>;
function f(s: number): Iterable<any>;
function* f(s: any): Iterable<any> { }
}