Skip to content

Commit 0f4e887

Browse files
Changed error message for annotated functions lacking return statements.
1 parent 1728f7c commit 0f4e887

25 files changed

+35
-35
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4051,7 +4051,7 @@ module ts {
40514051
}
40524052

40534053
// This function does not conform to the specification.
4054-
error(func.type, Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_have_a_return_expression_or_consist_of_a_single_throw_statement);
4054+
error(func.type, Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value_or_consist_of_a_single_throw_statement);
40554055
}
40564056

40574057
function checkFunctionExpression(node: FunctionExpression, contextualType?: Type, contextualMapper?: TypeMapper): Type {

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ module ts {
115115
The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: { code: 2119, category: DiagnosticCategory.Error, key: "The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter" },
116116
A_get_accessor_must_return_a_value_or_consist_of_a_single_throw_statement: { code: 2126, category: DiagnosticCategory.Error, key: "A 'get' accessor must return a value or consist of a single 'throw' statement." },
117117
Getter_and_setter_accessors_do_not_agree_in_visibility: { code: 2127, category: DiagnosticCategory.Error, key: "Getter and setter accessors do not agree in visibility." },
118-
A_function_whose_declared_type_is_neither_void_nor_any_must_have_a_return_expression_or_consist_of_a_single_throw_statement: { code: 2131, category: DiagnosticCategory.Error, key: "A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement." },
118+
A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value_or_consist_of_a_single_throw_statement: { code: 2131, category: DiagnosticCategory.Error, key: "A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement." },
119119
Untyped_function_calls_may_not_accept_type_arguments: { code: 2158, category: DiagnosticCategory.Error, key: "Untyped function calls may not accept type arguments." },
120120
The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: { code: 2120, category: DiagnosticCategory.Error, key: "The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter." },
121121
The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type: { code: 2121, category: DiagnosticCategory.Error, key: "The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type." },

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@
454454
"category": "Error",
455455
"code": 2127
456456
},
457-
"A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.": {
457+
"A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.": {
458458
"category": "Error",
459459
"code": 2131
460460
},

tests/baselines/reference/ParameterList5.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
==== tests/cases/compiler/ParameterList5.ts (3 errors) ====
22
function A(): (public B) => C {
33
~~~~~~~~~~~~~~~
4-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
4+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
55
~~~~~~~~
66
!!! A parameter property is only allowed in a constructor implementation.
77
~

tests/baselines/reference/ambientGetters.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
~
66
!!! '{' expected.
77
~~~~~~
8-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
8+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
99
}
1010

1111
declare class B {

tests/baselines/reference/conflictingTypeAnnotatedVar.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
~~~
55
!!! Duplicate identifier 'foo'.
66
~~~~~~
7-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
7+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
88
function foo(): number { }
99
~~~
1010
!!! Duplicate identifier 'foo'.
1111
~~~~~~
12-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
12+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.

tests/baselines/reference/errorOnContextuallyTypedReturnType.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
!!! Type 'void' is not assignable to type 'boolean'.
66
var n2: () => boolean = function ():boolean { }; // expect an error here
77
~~~~~~~
8-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
8+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
99

tests/baselines/reference/functionImplementationErrors.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
// Function implemetnation with non -void return type annotation with no return
4949
function f5(): number {
5050
~~~~~~
51-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
51+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
5252
}
5353

5454
var m;

tests/baselines/reference/functionWithThrowButNoReturn1.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
==== tests/cases/compiler/functionWithThrowButNoReturn1.ts (1 errors) ====
22
function fn(): number {
33
~~~~~~
4-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
4+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
55
throw new Error('NYI');
66
var t;
77
}

tests/baselines/reference/functionsMissingReturnStatementsAndExpressions.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
function f1(): string {
44
~~~~~~
5-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
5+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
66
// errors because there are no return statements
77
}
88

@@ -66,7 +66,7 @@
6666

6767
function f14(): number {
6868
~~~~~~
69-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
69+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
7070
// Not fine, since we can *only* consist of a single throw statement
7171
// if no return statements are present but we are annotated.
7272
throw undefined;

tests/baselines/reference/genericRecursiveImplicitConstructorErrors3.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
export class MemberName <A,B,C>{
44
static create<A,B,C>(arg1: any, arg2?: any, arg3?: any): MemberName {
55
~~~~~~~~~~
6-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
6+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
77
~~~~~~~~~~
88
!!! Generic type 'MemberName<A, B, C>' requires 3 type argument(s).
99
}

tests/baselines/reference/gettersAndSettersErrors.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
~~~
1818
!!! Accessors are only available when targeting ECMAScript 5 and higher.
1919
~~~~~~
20-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
20+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
2121
}
2222

2323
class E {

tests/baselines/reference/invalidReturnStatements.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
// all the following should be error
33
function fn1(): number { }
44
~~~~~~
5-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
5+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
66
function fn2(): string { }
77
~~~~~~
8-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
8+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
99
function fn3(): boolean { }
1010
~~~~~~~
11-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
11+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
1212
function fn4(): Date { }
1313
~~~~
14-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
14+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
1515
function fn7(): any { } // should be valid: any includes void
1616

1717
interface I { id: number }

tests/baselines/reference/missingReturnStatement.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
export class Bug {
44
public foo():string {
55
~~~~~~
6-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
6+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
77
}
88
}
99
}

tests/baselines/reference/missingReturnStatement1.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
class Foo {
33
foo(): number {
44
~~~~~~
5-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
5+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
66
//return 4;
77
}
88
}

tests/baselines/reference/multiLineErrors.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
~~~~~~~~~~~~~~
1010
}
1111
~
12-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
12+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
1313
{
1414
var x = 4;
1515
var y = 10;

tests/baselines/reference/parserErrorRecovery_Block3.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
class C {
33
private a(): boolean {
44
~~~~~~~
5-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
5+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
66

77
private b(): boolean {
88
~~~~~~~
99
!!! Statement expected.
1010
~~~~~~~
11-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
11+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
1212
}
1313
}

tests/baselines/reference/parserGenericsInTypeContexts1.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
function f2(): F<T> {
3232
~~~~
33-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
33+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
3434
~~~~
3535
!!! Cannot find name 'F'.
3636
}

tests/baselines/reference/parserGenericsInTypeContexts2.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
function f2(): F<X<T>, Y<Z<T>>> {
3232
~~~~~~~~~~~~~~~~
33-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
33+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
3434
~~~~~~~~~~~~~~~~
3535
!!! Cannot find name 'F'.
3636
}

tests/baselines/reference/parserParameterList5.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
==== tests/cases/conformance/parser/ecmascript5/ParameterLists/parserParameterList5.ts (3 errors) ====
22
function A(): (public B) => C {
33
~~~~~~~~~~~~~~~
4-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
4+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
55
~~~~~~~~
66
!!! A parameter property is only allowed in a constructor implementation.
77
~

tests/baselines/reference/parserSetAccessorWithTypeAnnotation1.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
~~~
55
!!! A 'set' accessor cannot have a return type annotation.
66
~~~~~~
7-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
7+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
88
}
99
}

tests/baselines/reference/recursiveFunctionTypes.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
function f2(): typeof g2 { }
2020
~~~~~~~~~
21-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
21+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
2222
function g2(): typeof f2 { }
2323
~~~~~~~~~
24-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
24+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
2525

2626
interface I<T> { }
2727
function f3(): I<typeof f3> { return f3; }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
==== tests/cases/compiler/returnTypeParameter.ts (2 errors) ====
22
function f<T>(a: T): T { } // error, no return statement
33
~
4-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
4+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
55
function f2<T>(a: T): T { return T; } // bug was that this satisfied the return statement requirement
66
~
77
!!! Cannot find name 'T'.

tests/baselines/reference/typeParameterUsedAsTypeParameterConstraint4.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
~~~~~~~~~~~
3636
!!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
3737
~
38-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
38+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
3939
~
4040
!!! Cannot find name 'V'.
4141
function bar<V extends T, W extends U>(): X { // error
4242
~
43-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
43+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
4444
~
4545
!!! Cannot find name 'X'.
4646
function baz<X extends W, Y extends V>(a: X, b: Y): T {
@@ -58,12 +58,12 @@
5858
~~~~~~~~~~~
5959
!!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
6060
~
61-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
61+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
6262
~
6363
!!! Cannot find name 'W'.
6464
function bar<V extends T, W extends U>(): Y { // error
6565
~
66-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
66+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
6767
~
6868
!!! Cannot find name 'Y'.
6969
function baz<X extends W, Y extends V>(a: X, b: Y): T {

tests/baselines/reference/unknownSymbols1.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
~~~~
1111
!!! Cannot find name 'asdf'.
1212
~~~~
13-
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
13+
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
1414
~~~~
1515
!!! Cannot find name 'asdf'.
1616
function foo2() {

0 commit comments

Comments
 (0)