mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
disallow statements between overloads
This commit is contained in:
parent
df3567c7db
commit
59b1e46102
@ -4872,47 +4872,101 @@ module ts {
|
||||
var hasOverloads = false;
|
||||
var bodyDeclaration: FunctionDeclaration;
|
||||
var lastSeenNonAmbientDeclaration: FunctionDeclaration;
|
||||
var previousDeclaration: FunctionDeclaration;
|
||||
|
||||
var declarations = symbol.declarations;
|
||||
var isConstructor = (symbol.flags & SymbolFlags.Constructor) !== 0;
|
||||
|
||||
function reportImplementationExpectedError(node: FunctionDeclaration): void {
|
||||
var seen = false;
|
||||
var subsequentNode = forEachChild(node.parent, c => {
|
||||
if (seen) {
|
||||
return c;
|
||||
}
|
||||
else {
|
||||
seen = c === node;
|
||||
}
|
||||
});
|
||||
if (subsequentNode) {
|
||||
if (subsequentNode.kind === node.kind) {
|
||||
var errorNode: Node = (<FunctionDeclaration>subsequentNode).name || subsequentNode;
|
||||
if (node.name && (<FunctionDeclaration>subsequentNode).name && node.name.text === (<FunctionDeclaration>subsequentNode).name.text) {
|
||||
// the only situation when this is possible (same kind\same name but different symbol) - mixed static and instance class members
|
||||
Debug.assert(node.kind === SyntaxKind.Method);
|
||||
Debug.assert((node.flags & NodeFlags.Static) !== (subsequentNode.flags & NodeFlags.Static));
|
||||
var diagnostic = node.flags & NodeFlags.Static ? Diagnostics.Function_overload_must_be_static : Diagnostics.Function_overload_must_not_be_static;
|
||||
error(errorNode, diagnostic);
|
||||
return;
|
||||
}
|
||||
else if ((<FunctionDeclaration>subsequentNode).body) {
|
||||
error(errorNode, Diagnostics.Function_implementation_name_must_be_0, identifierToString(node.name));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
var errorNode: Node = node.name || node;
|
||||
if (isConstructor) {
|
||||
error(errorNode, Diagnostics.Constructor_implementation_is_missing);
|
||||
}
|
||||
else {
|
||||
error(errorNode, Diagnostics.Function_implementation_is_missing);
|
||||
}
|
||||
}
|
||||
|
||||
// when checking exported function declarations across modules check only duplicate implementations
|
||||
// names and consistensy of modifiers are verified when we check local symbol
|
||||
var isExportSymbolInsideModule = symbol.parent && symbol.parent.flags & SymbolFlags.Module;
|
||||
for (var i = 0; i < declarations.length; i++) {
|
||||
var node = <FunctionDeclaration>declarations[i];
|
||||
var inAmbientContext = isInAmbientContext(node);
|
||||
var inAmbientContextOrInterface = node.parent.kind === SyntaxKind.InterfaceDeclaration || node.parent.kind === SyntaxKind.TypeLiteral || inAmbientContext;
|
||||
if (inAmbientContextOrInterface) {
|
||||
// check if declarations are consecutive only if they are non-ambient
|
||||
// 1. ambient declarations can be interleaved
|
||||
// i.e. this is legal
|
||||
// declare function foo();
|
||||
// declare function bar();
|
||||
// declare function foo();
|
||||
// 2. mixing ambient and non-ambient declarations is a separate error that will be reported - do not want to report an extra one
|
||||
previousDeclaration = undefined;
|
||||
}
|
||||
|
||||
if (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.Method || node.kind === SyntaxKind.Constructor) {
|
||||
var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck);
|
||||
someNodeFlags |= currentNodeFlags;
|
||||
allNodeFlags &= currentNodeFlags;
|
||||
|
||||
var inAmbientContext = isInAmbientContext(node);
|
||||
var inAmbientContextOrInterface = node.parent.kind === SyntaxKind.InterfaceDeclaration || node.parent.kind === SyntaxKind.TypeLiteral || inAmbientContext;
|
||||
if (!inAmbientContextOrInterface) {
|
||||
lastSeenNonAmbientDeclaration = node;
|
||||
if (node.body && bodyDeclaration) {
|
||||
if (isConstructor) {
|
||||
error(node, Diagnostics.Multiple_constructor_implementations_are_not_allowed);
|
||||
}
|
||||
else {
|
||||
error(node, Diagnostics.Duplicate_function_implementation);
|
||||
}
|
||||
}
|
||||
else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) {
|
||||
reportImplementationExpectedError(previousDeclaration);
|
||||
}
|
||||
|
||||
if (node.body) {
|
||||
if (bodyDeclaration) {
|
||||
if (isConstructor) {
|
||||
error(node, Diagnostics.Multiple_constructor_implementations_are_not_allowed);
|
||||
}
|
||||
else {
|
||||
error(node, Diagnostics.Duplicate_function_implementation);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!bodyDeclaration) {
|
||||
bodyDeclaration = node;
|
||||
}
|
||||
}
|
||||
else {
|
||||
hasOverloads = true;
|
||||
}
|
||||
|
||||
previousDeclaration = node;
|
||||
|
||||
if (!inAmbientContextOrInterface) {
|
||||
lastSeenNonAmbientDeclaration = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body) {
|
||||
if (isConstructor) {
|
||||
error(lastSeenNonAmbientDeclaration, Diagnostics.Constructor_implementation_expected);
|
||||
}
|
||||
else {
|
||||
error(lastSeenNonAmbientDeclaration, Diagnostics.Function_implementation_expected);
|
||||
}
|
||||
if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body) {
|
||||
reportImplementationExpectedError(lastSeenNonAmbientDeclaration);
|
||||
}
|
||||
|
||||
if (hasOverloads) {
|
||||
@ -4985,7 +5039,7 @@ module ts {
|
||||
}
|
||||
});
|
||||
|
||||
var commonDeclarationSpace = exportedDeclarationSpaces & nonExportedDeclarationSpaces
|
||||
var commonDeclarationSpace = exportedDeclarationSpaces & nonExportedDeclarationSpaces;
|
||||
|
||||
if (commonDeclarationSpace) {
|
||||
// declaration spaces for exported and non-exported declarations intersect
|
||||
|
||||
@ -158,9 +158,12 @@ module ts {
|
||||
Duplicate_number_index_signature: { code: 2233, category: DiagnosticCategory.Error, key: "Duplicate number index signature." },
|
||||
All_declarations_of_an_interface_must_have_identical_type_parameters: { code: 2234, category: DiagnosticCategory.Error, key: "All declarations of an interface must have identical type parameters." },
|
||||
Expression_resolves_to_variable_declaration_i_that_compiler_uses_to_initialize_rest_parameter: { code: 2235, category: DiagnosticCategory.Error, key: "Expression resolves to variable declaration '_i' that compiler uses to initialize rest parameter." },
|
||||
Constructor_implementation_expected: { code: 2240, category: DiagnosticCategory.Error, key: "Constructor implementation expected." },
|
||||
Function_implementation_name_must_be_0: { code: 2239, category: DiagnosticCategory.Error, key: "Function implementation name must be '{0}'." },
|
||||
Constructor_implementation_is_missing: { code: 2240, category: DiagnosticCategory.Error, key: "Constructor implementation is missing." },
|
||||
An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements: { code: 2245, category: DiagnosticCategory.Error, key: "An export assignment cannot be used in a module with other exported elements." },
|
||||
A_parameter_property_is_only_allowed_in_a_constructor_implementation: { code: 2246, category: DiagnosticCategory.Error, key: "A parameter property is only allowed in a constructor implementation." },
|
||||
Function_overload_must_be_static: { code: 2247, category: DiagnosticCategory.Error, key: "Function overload must be static." },
|
||||
Function_overload_must_not_be_static: { code: 2248, category: DiagnosticCategory.Error, key: "Function overload must not be static." },
|
||||
Circular_definition_of_import_alias_0: { code: 3000, category: DiagnosticCategory.Error, key: "Circular definition of import alias '{0}'." },
|
||||
Cannot_find_name_0: { code: 3001, category: DiagnosticCategory.Error, key: "Cannot find name '{0}'." },
|
||||
Module_0_has_no_exported_member_1: { code: 3002, category: DiagnosticCategory.Error, key: "Module '{0}' has no exported member '{1}'." },
|
||||
@ -276,7 +279,7 @@ module ts {
|
||||
Types_of_parameters_0_and_1_are_incompatible_Colon: { code: -9999999, category: DiagnosticCategory.Error, key: "Types of parameters '{0}' and '{1}' are incompatible:" },
|
||||
Unknown_identifier_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Unknown identifier '{0}'." },
|
||||
Property_0_is_inaccessible: { code: -9999999, category: DiagnosticCategory.Error, key: "Property '{0}' is inaccessible." },
|
||||
Function_implementation_expected: { code: -9999999, category: DiagnosticCategory.Error, key: "Function implementation expected." },
|
||||
Function_implementation_is_missing: { code: -9999999, category: DiagnosticCategory.Error, key: "Function implementation is missing." },
|
||||
Property_0_of_type_1_is_not_assignable_to_string_index_type_2: { code: -9999999, category: DiagnosticCategory.Error, key: "Property '{0}' of type '{1}' is not assignable to string index type '{2}'." },
|
||||
Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2: { code: -9999999, category: DiagnosticCategory.Error, key: "Property '{0}' of type '{1}' is not assignable to numeric index type '{2}'." },
|
||||
Numeric_index_type_0_is_not_assignable_to_string_index_type_1: { code: -9999999, category: DiagnosticCategory.Error, key: "Numeric index type '{0}' is not assignable to string index type '{1}'." },
|
||||
|
||||
@ -623,8 +623,12 @@
|
||||
"Expression resolves to variable declaration '_i' that compiler uses to initialize rest parameter.": {
|
||||
"category": "Error",
|
||||
"code": 2235
|
||||
},
|
||||
"Constructor implementation expected.": {
|
||||
},
|
||||
"Function implementation name must be '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 2239
|
||||
},
|
||||
"Constructor implementation is missing.": {
|
||||
"category": "Error",
|
||||
"code": 2240
|
||||
},
|
||||
@ -636,6 +640,14 @@
|
||||
"category": "Error",
|
||||
"code": 2246
|
||||
},
|
||||
"Function overload must be static.": {
|
||||
"category": "Error",
|
||||
"code": 2247
|
||||
},
|
||||
"Function overload must not be static.": {
|
||||
"category": "Error",
|
||||
"code": 2248
|
||||
},
|
||||
"Circular definition of import alias '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 3000
|
||||
@ -900,7 +912,6 @@
|
||||
"category": "Error",
|
||||
"code": 7020
|
||||
},
|
||||
|
||||
"Variable declaration list cannot be empty.": {
|
||||
"category": "Error",
|
||||
"code": -9999999
|
||||
@ -1121,7 +1132,7 @@
|
||||
"category": "Error",
|
||||
"code": -9999999
|
||||
},
|
||||
"Function implementation expected.": {
|
||||
"Function implementation is missing.": {
|
||||
"category": "Error",
|
||||
"code": -9999999
|
||||
},
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
class C {
|
||||
constructor();
|
||||
~~~~~~~~~~~~~~
|
||||
!!! Constructor implementation expected.
|
||||
!!! Constructor implementation is missing.
|
||||
foo();
|
||||
~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
}
|
||||
@ -2,6 +2,6 @@
|
||||
class C {
|
||||
constructor();
|
||||
~~~~~~~~~~~~~~
|
||||
!!! Constructor implementation expected.
|
||||
!!! Constructor implementation is missing.
|
||||
foo() { }
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
==== tests/cases/compiler/ClassDeclaration13.ts (1 errors) ====
|
||||
class C {
|
||||
foo();
|
||||
~~~~~~
|
||||
!!! Function implementation expected.
|
||||
bar() { }
|
||||
~~~
|
||||
!!! Function implementation name must be 'foo'.
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
==== tests/cases/compiler/ClassDeclaration14.ts (2 errors) ====
|
||||
class C {
|
||||
foo();
|
||||
~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
constructor();
|
||||
~~~~~~~~~~~~~~
|
||||
!!! Constructor implementation expected.
|
||||
!!! Constructor implementation is missing.
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
==== tests/cases/compiler/ClassDeclaration15.ts (1 errors) ====
|
||||
class C {
|
||||
foo();
|
||||
~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
constructor() { }
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
==== tests/cases/compiler/ClassDeclaration21.ts (1 errors) ====
|
||||
class C {
|
||||
0();
|
||||
~~~~
|
||||
!!! Function implementation expected.
|
||||
1() { }
|
||||
~
|
||||
!!! Function implementation name must be '0'.
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
==== tests/cases/compiler/ClassDeclaration22.ts (1 errors) ====
|
||||
class C {
|
||||
"foo"();
|
||||
~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
"bar"() { }
|
||||
~~~~~
|
||||
!!! Function implementation name must be '"foo"'.
|
||||
}
|
||||
@ -5,10 +5,10 @@
|
||||
}
|
||||
class List<U> implements IList<U> {
|
||||
data(): U;
|
||||
~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~~
|
||||
!!! Function implementation is missing.
|
||||
next(): string;
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~~
|
||||
!!! Function implementation is missing.
|
||||
}
|
||||
|
||||
@ -2,5 +2,5 @@
|
||||
class C {
|
||||
constructor();
|
||||
~~~~~~~~~~~~~~
|
||||
!!! Constructor implementation expected.
|
||||
!!! Constructor implementation is missing.
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
==== tests/cases/compiler/ClassDeclaration9.ts (1 errors) ====
|
||||
class C {
|
||||
foo();
|
||||
~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
==== tests/cases/compiler/FunctionDeclaration3.ts (1 errors) ====
|
||||
function foo();
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
@ -1,5 +1,5 @@
|
||||
==== tests/cases/compiler/FunctionDeclaration4.ts (1 errors) ====
|
||||
function foo();
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
function bar() { }
|
||||
function bar() { }
|
||||
~~~
|
||||
!!! Function implementation name must be 'foo'.
|
||||
@ -1,7 +1,7 @@
|
||||
==== tests/cases/compiler/FunctionDeclaration6.ts (1 errors) ====
|
||||
{
|
||||
function foo();
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
function bar() { }
|
||||
~~~
|
||||
!!! Function implementation name must be 'foo'.
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
==== tests/cases/compiler/FunctionDeclaration7.ts (1 errors) ====
|
||||
module M {
|
||||
function foo();
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
==== tests/cases/compiler/assignmentCompatFunctionsWithOptionalArgs.ts (3 errors) ====
|
||||
function foo(x: { id: number; name?: string; }): void;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
foo({ id: 1234 }); // Ok
|
||||
foo({ id: 1234, name: "hello" }); // Ok
|
||||
foo({ id: 1234, name: false }); // Error, name of wrong type
|
||||
|
||||
@ -8,8 +8,8 @@
|
||||
}
|
||||
|
||||
function Foo(); // error
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
~~~
|
||||
!!! Duplicate identifier 'Foo'.
|
||||
function F1(s:string);
|
||||
|
||||
@ -10,19 +10,19 @@
|
||||
}
|
||||
|
||||
function Foo();
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Duplicate identifier 'Foo'.
|
||||
|
||||
function F1(s:string) {return s;}
|
||||
~~
|
||||
!!! Function implementation name must be 'Foo'.
|
||||
function F1(a:any) { return a;} // error - duplicate identifier
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Duplicate function implementation.
|
||||
|
||||
function Goo(s:string); // error - no implementation
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
|
||||
declare function Gar(s:String); // expect no error
|
||||
|
||||
|
||||
@ -4,8 +4,8 @@
|
||||
~~~
|
||||
!!! Cannot find name 'Foo'.
|
||||
function Foo(s:string):Foo;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
~~~
|
||||
!!! Cannot find name 'Foo'.
|
||||
class Foo {
|
||||
|
||||
@ -4,8 +4,8 @@
|
||||
~~~
|
||||
!!! Cannot find name 'Foo'.
|
||||
function Foo(s:string):Foo;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
~~~
|
||||
!!! Cannot find name 'Foo'.
|
||||
class Foo {
|
||||
|
||||
@ -3,8 +3,8 @@
|
||||
~~~
|
||||
!!! Cannot find name 'Foo'.
|
||||
function Foo(s:string):Foo;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
~~~
|
||||
!!! Cannot find name 'Foo'.
|
||||
class Foo {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
==== tests/cases/compiler/classOverloadForFunction2.ts (2 errors) ====
|
||||
function bar(): string;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
class bar {}
|
||||
~~~
|
||||
!!! Duplicate identifier 'bar'.
|
||||
@ -2,7 +2,7 @@
|
||||
class C {
|
||||
foo(): string;
|
||||
foo(x): number;
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
bar(x): any { }
|
||||
~~~
|
||||
!!! Function implementation name must be 'foo'.
|
||||
}
|
||||
@ -1,8 +1,10 @@
|
||||
==== tests/cases/compiler/classWithOverloadImplementationOfWrongName2.ts (1 errors) ====
|
||||
==== tests/cases/compiler/classWithOverloadImplementationOfWrongName2.ts (2 errors) ====
|
||||
class C {
|
||||
foo(): string;
|
||||
bar(x): any { }
|
||||
~~~
|
||||
!!! Function implementation name must be 'foo'.
|
||||
foo(x): number;
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
==== tests/cases/compiler/crashOnMethodSignatures.ts (1 errors) ====
|
||||
class A {
|
||||
a(completed: () => any): void;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~
|
||||
!!! Function implementation is missing.
|
||||
}
|
||||
|
||||
@ -4,8 +4,8 @@
|
||||
export function f(x:number)=>2*x;
|
||||
~~
|
||||
!!! Block or ';' expected.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~
|
||||
!!! Function implementation is missing.
|
||||
~
|
||||
!!! Cannot find name 'x'.
|
||||
export module X.Y.Z {
|
||||
|
||||
@ -14,11 +14,11 @@
|
||||
~~~~~
|
||||
!!! Cannot compile external modules unless the '--module' flag is provided.
|
||||
public getDay():number;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~~~~
|
||||
!!! Function implementation is missing.
|
||||
public getXDate():number;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~~~~~~
|
||||
!!! Function implementation is missing.
|
||||
// etc.
|
||||
|
||||
// Called as a function
|
||||
@ -34,24 +34,23 @@
|
||||
constructor(value: number);
|
||||
constructor();
|
||||
~~~~~~~~~~~~~~
|
||||
!!! Constructor implementation expected.
|
||||
!!! Constructor implementation is missing.
|
||||
|
||||
static parse(string: string): number;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~~~
|
||||
!!! Function implementation is missing.
|
||||
static UTC(year: number, month: number): number;
|
||||
static UTC(year: number, month: number, date: number): number;
|
||||
static UTC(year: number, month: number, date: number, hours: number): number;
|
||||
static UTC(year: number, month: number, date: number, hours: number, minutes: number): number;
|
||||
static UTC(year: number, month: number, date: number, hours: number, minutes: number, seconds: number): number;
|
||||
static UTC(year: number, month: number, date: number, hours: number, minutes: number, seconds: number,
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
ms: number): number;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
static now(): number;
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
}
|
||||
}
|
||||
~
|
||||
|
||||
@ -32,9 +32,9 @@
|
||||
}
|
||||
|
||||
function over();
|
||||
~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
function overrr() {
|
||||
~~~~~~
|
||||
!!! Function implementation name must be 'over'.
|
||||
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
==== tests/cases/conformance/functions/functionOverloadErrors.ts (15 errors) ====
|
||||
==== tests/cases/conformance/functions/functionOverloadErrors.ts (14 errors) ====
|
||||
//Function overload signature with initializer
|
||||
function fn1(x = 3);
|
||||
~~~~~
|
||||
@ -86,8 +86,6 @@
|
||||
//Function overloads with differing export
|
||||
module M {
|
||||
export function fn1();
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Overload signatures must all be exported or not exported.
|
||||
function fn1(n: string);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
==== tests/cases/compiler/functionOverloadImplementationOfWrongName.ts (1 errors) ====
|
||||
function foo(x);
|
||||
function foo(x, y);
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
function bar() { }
|
||||
function bar() { }
|
||||
~~~
|
||||
!!! Function implementation name must be 'foo'.
|
||||
@ -1,6 +1,8 @@
|
||||
==== tests/cases/compiler/functionOverloadImplementationOfWrongName2.ts (1 errors) ====
|
||||
==== tests/cases/compiler/functionOverloadImplementationOfWrongName2.ts (2 errors) ====
|
||||
function foo(x);
|
||||
function bar() { }
|
||||
~~~
|
||||
!!! Function implementation name must be 'foo'.
|
||||
function foo(x, y);
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
6
tests/baselines/reference/functionOverloads1.errors.txt
Normal file
6
tests/baselines/reference/functionOverloads1.errors.txt
Normal file
@ -0,0 +1,6 @@
|
||||
==== tests/cases/compiler/functionOverloads1.ts (1 errors) ====
|
||||
function foo();
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
1+1;
|
||||
function foo():string { return "a" }
|
||||
@ -1,4 +1,4 @@
|
||||
==== tests/cases/compiler/functionOverloads3.ts (1 errors) ====
|
||||
function foo():string;
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
@ -5,8 +5,8 @@
|
||||
return ns.toString();
|
||||
}
|
||||
private foo(s: string): string;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
}
|
||||
|
||||
class e {
|
||||
@ -15,6 +15,6 @@
|
||||
}
|
||||
private foo(s: string): string;
|
||||
private foo(n: number): string;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
}
|
||||
@ -2,7 +2,7 @@
|
||||
class C {
|
||||
foo(): string;
|
||||
foo(x): number;
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
x = 1;
|
||||
}
|
||||
@ -3,8 +3,8 @@
|
||||
class IDirectChildrenMap {
|
||||
// Decided to enforce a semicolon after declarations
|
||||
hasOwnProperty(objectId: number): boolean
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~~~~~~~~~~~~
|
||||
!!! Function implementation is missing.
|
||||
[objectId: number]: IHeapObjectProperty[]
|
||||
}
|
||||
var directChildrenMap = <IDirectChildrenMap>{};
|
||||
@ -1,36 +1,36 @@
|
||||
==== tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionOverloadMixingStaticAndInstance.ts (8 errors) ====
|
||||
class C {
|
||||
foo();
|
||||
~~~~~~
|
||||
!!! Function implementation expected.
|
||||
static foo(); // error
|
||||
~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
~~~
|
||||
!!! Function overload must not be static.
|
||||
}
|
||||
|
||||
class D {
|
||||
static foo();
|
||||
~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
foo(); // error
|
||||
~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
~~~
|
||||
!!! Function overload must be static.
|
||||
}
|
||||
|
||||
class E<T> {
|
||||
foo(x: T);
|
||||
~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
static foo(x: number); // error
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
~~~
|
||||
!!! Function overload must not be static.
|
||||
}
|
||||
|
||||
class F<T> {
|
||||
static foo(x: number);
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
foo(x: T); // error
|
||||
~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
~~~
|
||||
!!! Function overload must be static.
|
||||
}
|
||||
@ -1,35 +1,39 @@
|
||||
==== tests/cases/compiler/mixingStaticAndInstanceOverloads.ts (4 errors) ====
|
||||
==== tests/cases/compiler/mixingStaticAndInstanceOverloads.ts (6 errors) ====
|
||||
class C1 {
|
||||
// ERROR
|
||||
foo1(n: number);
|
||||
foo1(s: string);
|
||||
~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
static foo1(a) { }
|
||||
~~~~
|
||||
!!! Function overload must not be static.
|
||||
}
|
||||
class C2 {
|
||||
// ERROR
|
||||
static foo2(n: number);
|
||||
static foo2(s: string);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
foo2(a) { }
|
||||
~~~~
|
||||
!!! Function overload must be static.
|
||||
}
|
||||
class C3 {
|
||||
// ERROR
|
||||
foo3(n: number);
|
||||
static foo3(s: string);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~~
|
||||
!!! Function overload must not be static.
|
||||
foo3(a) { }
|
||||
~~~~
|
||||
!!! Function overload must be static.
|
||||
}
|
||||
class C4 {
|
||||
// ERROR
|
||||
static foo4(n: number);
|
||||
foo4(s: string);
|
||||
~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~~
|
||||
!!! Function overload must be static.
|
||||
static foo4(a) { }
|
||||
~~~~
|
||||
!!! Function overload must not be static.
|
||||
}
|
||||
class C5 {
|
||||
// OK
|
||||
|
||||
@ -23,8 +23,8 @@
|
||||
!!! Block or ';' expected.
|
||||
~
|
||||
!!! Unexpected token. A constructor, method, accessor, or property was expected.
|
||||
~~~
|
||||
!!! Function implementation expected.
|
||||
~
|
||||
!!! Function implementation is missing.
|
||||
}
|
||||
|
||||
interface I2<T> {
|
||||
@ -41,8 +41,8 @@
|
||||
!!! Block or ';' expected.
|
||||
~
|
||||
!!! Unexpected token. A constructor, method, accessor, or property was expected.
|
||||
~~~
|
||||
!!! Function implementation expected.
|
||||
~
|
||||
!!! Function implementation is missing.
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
==== tests/cases/compiler/overloadModifiersMustAgree.ts (5 errors) ====
|
||||
==== tests/cases/compiler/overloadModifiersMustAgree.ts (4 errors) ====
|
||||
class baz {
|
||||
public foo();
|
||||
~~~
|
||||
@ -10,8 +10,6 @@
|
||||
~~~
|
||||
!!! Overload signatures must all be ambient or non-ambient.
|
||||
export function bar(s: string);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Overload signatures must all be exported or not exported.
|
||||
function bar(s?: string) { }
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
class C {
|
||||
constructor();
|
||||
~~~~~~~~~~~~~~
|
||||
!!! Constructor implementation expected.
|
||||
!!! Constructor implementation is missing.
|
||||
foo();
|
||||
~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
}
|
||||
@ -2,6 +2,6 @@
|
||||
class C {
|
||||
constructor();
|
||||
~~~~~~~~~~~~~~
|
||||
!!! Constructor implementation expected.
|
||||
!!! Constructor implementation is missing.
|
||||
foo() { }
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
==== tests/cases/conformance/parser/ecmascript5/ClassDeclarations/parserClassDeclaration13.ts (1 errors) ====
|
||||
class C {
|
||||
foo();
|
||||
~~~~~~
|
||||
!!! Function implementation expected.
|
||||
bar() { }
|
||||
~~~
|
||||
!!! Function implementation name must be 'foo'.
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
==== tests/cases/conformance/parser/ecmascript5/ClassDeclarations/parserClassDeclaration14.ts (2 errors) ====
|
||||
class C {
|
||||
foo();
|
||||
~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
constructor();
|
||||
~~~~~~~~~~~~~~
|
||||
!!! Constructor implementation expected.
|
||||
!!! Constructor implementation is missing.
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
==== tests/cases/conformance/parser/ecmascript5/ClassDeclarations/parserClassDeclaration15.ts (1 errors) ====
|
||||
class C {
|
||||
foo();
|
||||
~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
constructor() { }
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
==== tests/cases/conformance/parser/ecmascript5/ClassDeclarations/parserClassDeclaration21.ts (1 errors) ====
|
||||
class C {
|
||||
0();
|
||||
~~~~
|
||||
!!! Function implementation expected.
|
||||
1() { }
|
||||
~
|
||||
!!! Function implementation name must be '0'.
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
==== tests/cases/conformance/parser/ecmascript5/ClassDeclarations/parserClassDeclaration22.ts (1 errors) ====
|
||||
class C {
|
||||
"foo"();
|
||||
~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
"bar"() { }
|
||||
~~~~~
|
||||
!!! Function implementation name must be '"foo"'.
|
||||
}
|
||||
@ -5,10 +5,10 @@
|
||||
}
|
||||
class List<U> implements IList<U> {
|
||||
data(): U;
|
||||
~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~~
|
||||
!!! Function implementation is missing.
|
||||
next(): string;
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~~
|
||||
!!! Function implementation is missing.
|
||||
}
|
||||
|
||||
@ -2,5 +2,5 @@
|
||||
class C {
|
||||
constructor();
|
||||
~~~~~~~~~~~~~~
|
||||
!!! Constructor implementation expected.
|
||||
!!! Constructor implementation is missing.
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
==== tests/cases/conformance/parser/ecmascript5/ClassDeclarations/parserClassDeclaration9.ts (1 errors) ====
|
||||
class C {
|
||||
foo();
|
||||
~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
}
|
||||
@ -5,5 +5,5 @@
|
||||
~
|
||||
!!! '(' expected.
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! Constructor implementation expected.
|
||||
!!! Constructor implementation is missing.
|
||||
}
|
||||
@ -2,5 +2,5 @@
|
||||
function =>
|
||||
~~
|
||||
!!! Identifier expected.
|
||||
~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
|
||||
!!! Function implementation is missing.
|
||||
@ -8,5 +8,5 @@
|
||||
!!! ',' expected.
|
||||
|
||||
!!! ')' expected.
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
|
||||
!!! Function implementation is missing.
|
||||
@ -2,5 +2,5 @@
|
||||
function f() => 4;
|
||||
~~
|
||||
!!! Block or ';' expected.
|
||||
~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~
|
||||
!!! Function implementation is missing.
|
||||
@ -2,8 +2,8 @@
|
||||
function f(p: A) => p;
|
||||
~~
|
||||
!!! Block or ';' expected.
|
||||
~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~
|
||||
!!! Function implementation is missing.
|
||||
~
|
||||
!!! Cannot find name 'A'.
|
||||
~
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
!!! Type expected.
|
||||
~
|
||||
!!! Identifier expected.
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~~~~
|
||||
!!! Function implementation is missing.
|
||||
}
|
||||
~
|
||||
!!! Declaration or statement expected.
|
||||
@ -1,4 +1,4 @@
|
||||
==== tests/cases/conformance/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration3.ts (1 errors) ====
|
||||
function foo();
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
@ -1,5 +1,5 @@
|
||||
==== tests/cases/conformance/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration4.ts (1 errors) ====
|
||||
function foo();
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
function bar() { }
|
||||
function bar() { }
|
||||
~~~
|
||||
!!! Function implementation name must be 'foo'.
|
||||
@ -1,7 +1,7 @@
|
||||
==== tests/cases/conformance/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration6.ts (1 errors) ====
|
||||
{
|
||||
function foo();
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
function bar() { }
|
||||
~~~
|
||||
!!! Function implementation name must be 'foo'.
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
==== tests/cases/conformance/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration7.ts (1 errors) ====
|
||||
module M {
|
||||
function foo();
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
==== tests/cases/conformance/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration10.ts (2 errors) ====
|
||||
function data(): string;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~~
|
||||
!!! Function implementation is missing.
|
||||
function next(): string;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~~
|
||||
!!! Function implementation is missing.
|
||||
|
||||
@ -11,8 +11,8 @@
|
||||
function Foo () # { }
|
||||
|
||||
!!! Invalid character.
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
4+:5
|
||||
~
|
||||
!!! Expression expected.
|
||||
|
||||
@ -10,8 +10,8 @@
|
||||
|
||||
// just want to make sure this one doesn't crash the compiler
|
||||
function Foo();
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! Function implementation expected.
|
||||
~~~
|
||||
!!! Function implementation is missing.
|
||||
class Foo {
|
||||
~~~
|
||||
!!! Duplicate identifier 'Foo'.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user