Skip to content

Commit

Permalink
Changed error message for annotated functions lacking return statements.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRosenwasser committed Jul 21, 2014
1 parent 1728f7c commit 0f4e887
Show file tree
Hide file tree
Showing 25 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4051,7 +4051,7 @@ module ts {
}

// This function does not conform to the specification.
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);
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);
}

function checkFunctionExpression(node: FunctionExpression, contextualType?: Type, contextualMapper?: TypeMapper): Type {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diagnosticInformationMap.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ module ts {
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" },
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." },
Getter_and_setter_accessors_do_not_agree_in_visibility: { code: 2127, category: DiagnosticCategory.Error, key: "Getter and setter accessors do not agree in visibility." },
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." },
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." },
Untyped_function_calls_may_not_accept_type_arguments: { code: 2158, category: DiagnosticCategory.Error, key: "Untyped function calls may not accept type arguments." },
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." },
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." },
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@
"category": "Error",
"code": 2127
},
"A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.": {
"A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.": {
"category": "Error",
"code": 2131
},
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/ParameterList5.errors.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
==== tests/cases/compiler/ParameterList5.ts (3 errors) ====
function A(): (public B) => C {
~~~~~~~~~~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
~~~~~~~~
!!! A parameter property is only allowed in a constructor implementation.
~
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/ambientGetters.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
~
!!! '{' expected.
~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
}

declare class B {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
~~~
!!! Duplicate identifier 'foo'.
~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
function foo(): number { }
~~~
!!! Duplicate identifier 'foo'.
~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
!!! Type 'void' is not assignable to type 'boolean'.
var n2: () => boolean = function ():boolean { }; // expect an error here
~~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
// Function implemetnation with non -void return type annotation with no return
function f5(): number {
~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
}

var m;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
==== tests/cases/compiler/functionWithThrowButNoReturn1.ts (1 errors) ====
function fn(): number {
~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
throw new Error('NYI');
var t;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

Expand Down Expand Up @@ -66,7 +66,7 @@

function f14(): number {
~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
// Not fine, since we can *only* consist of a single throw statement
// if no return statements are present but we are annotated.
throw undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export class MemberName <A,B,C>{
static create<A,B,C>(arg1: any, arg2?: any, arg3?: any): MemberName {
~~~~~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
~~~~~~~~~~
!!! Generic type 'MemberName<A, B, C>' requires 3 type argument(s).
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
~~~
!!! Accessors are only available when targeting ECMAScript 5 and higher.
~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
}

class E {
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/invalidReturnStatements.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
// all the following should be error
function fn1(): number { }
~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
function fn2(): string { }
~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
function fn3(): boolean { }
~~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
function fn4(): Date { }
~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
function fn7(): any { } // should be valid: any includes void

interface I { id: number }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export class Bug {
public foo():string {
~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class Foo {
foo(): number {
~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
//return 4;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/multiLineErrors.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
~~~~~~~~~~~~~~
}
~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
{
var x = 4;
var y = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
class C {
private a(): boolean {
~~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.

private b(): boolean {
~~~~~~~
!!! Statement expected.
~~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

function f2(): F<T> {
~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
~~~~
!!! Cannot find name 'F'.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

function f2(): F<X<T>, Y<Z<T>>> {
~~~~~~~~~~~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
~~~~~~~~~~~~~~~~
!!! Cannot find name 'F'.
}
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/parserParameterList5.errors.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
==== tests/cases/conformance/parser/ecmascript5/ParameterLists/parserParameterList5.ts (3 errors) ====
function A(): (public B) => C {
~~~~~~~~~~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
~~~~~~~~
!!! A parameter property is only allowed in a constructor implementation.
~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
~~~
!!! A 'set' accessor cannot have a return type annotation.
~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
}
}
4 changes: 2 additions & 2 deletions tests/baselines/reference/recursiveFunctionTypes.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

function f2(): typeof g2 { }
~~~~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
function g2(): typeof f2 { }
~~~~~~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.

interface I<T> { }
function f3(): I<typeof f3> { return f3; }
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/returnTypeParameter.errors.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
==== tests/cases/compiler/returnTypeParameter.ts (2 errors) ====
function f<T>(a: T): T { } // error, no return statement
~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
function f2<T>(a: T): T { return T; } // bug was that this satisfied the return statement requirement
~
!!! Cannot find name 'T'.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
~~~~~~~~~~~
!!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
~
!!! Cannot find name 'V'.
function bar<V extends T, W extends U>(): X { // error
~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
~
!!! Cannot find name 'X'.
function baz<X extends W, Y extends V>(a: X, b: Y): T {
Expand All @@ -58,12 +58,12 @@
~~~~~~~~~~~
!!! Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
~
!!! Cannot find name 'W'.
function bar<V extends T, W extends U>(): Y { // error
~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
~
!!! Cannot find name 'Y'.
function baz<X extends W, Y extends V>(a: X, b: Y): T {
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/unknownSymbols1.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
~~~~
!!! Cannot find name 'asdf'.
~~~~
!!! A function whose declared type is neither 'void' nor 'any' must have a 'return' expression or consist of a single 'throw' statement.
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
~~~~
!!! Cannot find name 'asdf'.
function foo2() {
Expand Down

0 comments on commit 0f4e887

Please sign in to comment.