Changed error message for annotated functions lacking return statements.
This commit is contained in:
parent
1728f7c654
commit
0f4e887155
|
@ -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 {
|
||||
|
|
|
@ -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." },
|
||||
|
|
|
@ -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
|
||||
},
|
||||
|
|
|
@ -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.
|
||||
~
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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.
|
|
@ -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.
|
||||
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
|
|
@ -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).
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
}
|
|
@ -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'.
|
||||
}
|
||||
|
|
|
@ -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'.
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
~
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
}
|
|
@ -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; }
|
||||
|
|
|
@ -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'.
|
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue