Skip to content

Commit 623507c

Browse files
committed
Disallow return expressions in a generator
1 parent 21415af commit 623507c

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

src/compiler/checker.ts

+3
Original file line numberDiff line numberDiff line change
@@ -9720,6 +9720,9 @@ module ts {
97209720
if (func.kind === SyntaxKind.SetAccessor) {
97219721
error(node.expression, Diagnostics.Setters_cannot_return_a_value);
97229722
}
9723+
else if (func.asteriskToken) {
9724+
error(node.expression, Diagnostics.A_return_statement_cannot_specify_a_value_in_a_generator_function);
9725+
}
97239726
else {
97249727
if (func.kind === SyntaxKind.Constructor) {
97259728
if (!isTypeAssignableTo(exprType, returnType)) {

src/compiler/diagnosticInformationMap.generated.ts

+1
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ module ts {
366366
An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments: { code: 2499, category: DiagnosticCategory.Error, key: "An interface can only extend an identifier/qualified-name with optional type arguments." },
367367
A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments: { code: 2500, category: DiagnosticCategory.Error, key: "A class can only implement an identifier/qualified-name with optional type arguments." },
368368
A_rest_element_cannot_contain_a_binding_pattern: { code: 2501, category: DiagnosticCategory.Error, key: "A rest element cannot contain a binding pattern." },
369+
A_return_statement_cannot_specify_a_value_in_a_generator_function: { code: 2502, category: DiagnosticCategory.Error, key: "A return statement cannot specify a value in a generator function." },
369370
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
370371
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
371372
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },

src/compiler/diagnosticMessages.json

+4
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,10 @@
14531453
"category": "Error",
14541454
"code": 2501
14551455
},
1456+
"A return statement cannot specify a value in a generator function.": {
1457+
"category": "Error",
1458+
"code": 2502
1459+
},
14561460

14571461
"Import declaration '{0}' is using private name '{1}'.": {
14581462
"category": "Error",

0 commit comments

Comments
 (0)