do not crash if overloads cannot be merged under one symbol
This commit is contained in:
parent
bd39847d6c
commit
07626cbe89
|
@ -11352,11 +11352,15 @@ namespace ts {
|
|||
const errorNode: Node = (<FunctionLikeDeclaration>subsequentNode).name || subsequentNode;
|
||||
// TODO(jfreeman): These are methods, so handle computed name case
|
||||
if (node.name && (<FunctionLikeDeclaration>subsequentNode).name && (<Identifier>node.name).text === (<Identifier>(<FunctionLikeDeclaration>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.MethodDeclaration || node.kind === SyntaxKind.MethodSignature);
|
||||
Debug.assert((node.flags & NodeFlags.Static) !== (subsequentNode.flags & NodeFlags.Static));
|
||||
const diagnostic = node.flags & NodeFlags.Static ? Diagnostics.Function_overload_must_be_static : Diagnostics.Function_overload_must_not_be_static;
|
||||
error(errorNode, diagnostic);
|
||||
// we can get here in two cases
|
||||
// 1. mixed static and instance class members
|
||||
// 2. something with the same name was defined before the set of overloads that prevents them from merging
|
||||
// here we'll report error only for the first case since for second we should already report error in binder
|
||||
if ((node.flags & NodeFlags.Static) !== (subsequentNode.flags & NodeFlags.Static)) {
|
||||
const diagnostic = node.flags & NodeFlags.Static ? Diagnostics.Function_overload_must_be_static : Diagnostics.Function_overload_must_not_be_static;
|
||||
error(errorNode, diagnostic);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (nodeIsPresent((<FunctionLikeDeclaration>subsequentNode).body)) {
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
tests/cases/compiler/mixedStaticAndInstanceClassMembers.ts(4,5): error TS2387: Function overload must be static.
|
||||
tests/cases/compiler/mixedStaticAndInstanceClassMembers.ts(12,12): error TS2388: Function overload must not be static.
|
||||
tests/cases/compiler/mixedStaticAndInstanceClassMembers.ts(13,5): error TS2387: Function overload must be static.
|
||||
|
||||
|
||||
==== tests/cases/compiler/mixedStaticAndInstanceClassMembers.ts (3 errors) ====
|
||||
class A {
|
||||
f() {}
|
||||
static m1 (a: string): void;
|
||||
m1 (a: number): void;
|
||||
~~
|
||||
!!! error TS2387: Function overload must be static.
|
||||
m1 (a: any): void {
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
f() {}
|
||||
m1 (a: string): void;
|
||||
static m1 (a: number): void;
|
||||
~~
|
||||
!!! error TS2388: Function overload must not be static.
|
||||
m1 (a: any): void {
|
||||
~~
|
||||
!!! error TS2387: Function overload must be static.
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
//// [mixedStaticAndInstanceClassMembers.ts]
|
||||
class A {
|
||||
f() {}
|
||||
static m1 (a: string): void;
|
||||
m1 (a: number): void;
|
||||
m1 (a: any): void {
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
f() {}
|
||||
m1 (a: string): void;
|
||||
static m1 (a: number): void;
|
||||
m1 (a: any): void {
|
||||
}
|
||||
}
|
||||
|
||||
//// [mixedStaticAndInstanceClassMembers.js]
|
||||
var A = (function () {
|
||||
function A() {
|
||||
}
|
||||
A.prototype.f = function () { };
|
||||
A.prototype.m1 = function (a) {
|
||||
};
|
||||
return A;
|
||||
})();
|
||||
var B = (function () {
|
||||
function B() {
|
||||
}
|
||||
B.prototype.f = function () { };
|
||||
B.prototype.m1 = function (a) {
|
||||
};
|
||||
return B;
|
||||
})();
|
|
@ -0,0 +1,23 @@
|
|||
tests/cases/compiler/nonMergedDeclarationsAndOverloads.ts(2,5): error TS2300: Duplicate identifier 'm1'.
|
||||
tests/cases/compiler/nonMergedDeclarationsAndOverloads.ts(4,5): error TS2300: Duplicate identifier 'm1'.
|
||||
tests/cases/compiler/nonMergedDeclarationsAndOverloads.ts(5,5): error TS2300: Duplicate identifier 'm1'.
|
||||
tests/cases/compiler/nonMergedDeclarationsAndOverloads.ts(6,5): error TS2300: Duplicate identifier 'm1'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/nonMergedDeclarationsAndOverloads.ts (4 errors) ====
|
||||
class A {
|
||||
m1: string;
|
||||
~~
|
||||
!!! error TS2300: Duplicate identifier 'm1'.
|
||||
f() {}
|
||||
m1 (a: string): void;
|
||||
~~
|
||||
!!! error TS2300: Duplicate identifier 'm1'.
|
||||
m1 (a: number): void;
|
||||
~~
|
||||
!!! error TS2300: Duplicate identifier 'm1'.
|
||||
m1 (a: any): void {
|
||||
~~
|
||||
!!! error TS2300: Duplicate identifier 'm1'.
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
//// [nonMergedDeclarationsAndOverloads.ts]
|
||||
class A {
|
||||
m1: string;
|
||||
f() {}
|
||||
m1 (a: string): void;
|
||||
m1 (a: number): void;
|
||||
m1 (a: any): void {
|
||||
}
|
||||
}
|
||||
|
||||
//// [nonMergedDeclarationsAndOverloads.js]
|
||||
var A = (function () {
|
||||
function A() {
|
||||
}
|
||||
A.prototype.f = function () { };
|
||||
A.prototype.m1 = function (a) {
|
||||
};
|
||||
return A;
|
||||
})();
|
15
tests/cases/compiler/mixedStaticAndInstanceClassMembers.ts
Normal file
15
tests/cases/compiler/mixedStaticAndInstanceClassMembers.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
class A {
|
||||
f() {}
|
||||
static m1 (a: string): void;
|
||||
m1 (a: number): void;
|
||||
m1 (a: any): void {
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
f() {}
|
||||
m1 (a: string): void;
|
||||
static m1 (a: number): void;
|
||||
m1 (a: any): void {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
class A {
|
||||
m1: string;
|
||||
f() {}
|
||||
m1 (a: string): void;
|
||||
m1 (a: number): void;
|
||||
m1 (a: any): void {
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue