Skip to content

Commit ba57472

Browse files
committed
Check that private properties originate in the same declaration
1 parent 1eb924f commit ba57472

File tree

4 files changed

+90
-4
lines changed

4 files changed

+90
-4
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2888,10 +2888,12 @@ module ts {
28882888
}
28892889

28902890
if (getDeclarationFlagsFromSymbol(sourceProp) & NodeFlags.Private || getDeclarationFlagsFromSymbol(targetProp) & NodeFlags.Private) {
2891-
if (reportErrors) {
2892-
reportError(Diagnostics.Private_property_0_cannot_be_reimplemented, symbolToString(targetProp));
2891+
if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) {
2892+
if (reportErrors) {
2893+
reportError(Diagnostics.Private_property_0_cannot_be_reimplemented, symbolToString(targetProp));
2894+
}
2895+
return false;
28932896
}
2894-
return false;
28952897
}
28962898
if (!isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors)) {
28972899
if (reportErrors) {
@@ -4338,7 +4340,7 @@ module ts {
43384340
var widenedType = getWidenedType(exprType, /*supressNoImplicitAnyErrors*/ true);
43394341
if (!(isTypeAssignableTo(targetType, widenedType))) {
43404342
checkTypeAssignableTo(exprType, targetType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other_Colon, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other);
4341-
}
4343+
}
43424344
}
43434345
return targetType;
43444346
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//// [objectTypesIdentityWithPrivates3.ts]
2+
interface T1 { }
3+
interface T2 { z }
4+
5+
class C1<T> {
6+
private x;
7+
}
8+
9+
class C2 extends C1<T1> {
10+
y;
11+
}
12+
13+
var c1: C1<T2>;
14+
<C2>c1; // Should succeed (private x originates in the same declaration)
15+
16+
//// [objectTypesIdentityWithPrivates3.js]
17+
var __extends = this.__extends || function (d, b) {
18+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
19+
function __() { this.constructor = d; }
20+
__.prototype = b.prototype;
21+
d.prototype = new __();
22+
};
23+
var C1 = (function () {
24+
function C1() {
25+
}
26+
return C1;
27+
})();
28+
var C2 = (function (_super) {
29+
__extends(C2, _super);
30+
function C2() {
31+
_super.apply(this, arguments);
32+
}
33+
return C2;
34+
})(C1);
35+
var c1;
36+
c1; // Should succeed (private x originates in the same declaration)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
=== tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3.ts ===
2+
interface T1 { }
3+
>T1 : T1
4+
5+
interface T2 { z }
6+
>T2 : T2
7+
>z : any
8+
9+
class C1<T> {
10+
>C1 : C1<T>
11+
>T : T
12+
13+
private x;
14+
>x : any
15+
}
16+
17+
class C2 extends C1<T1> {
18+
>C2 : C2
19+
>C1 : C1<T>
20+
>T1 : T1
21+
22+
y;
23+
>y : any
24+
}
25+
26+
var c1: C1<T2>;
27+
>c1 : C1<T2>
28+
>C1 : C1<T>
29+
>T2 : T2
30+
31+
<C2>c1; // Should succeed (private x originates in the same declaration)
32+
><C2>c1 : C2
33+
>C2 : C2
34+
>c1 : C1<T2>
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
interface T1 { }
2+
interface T2 { z }
3+
4+
class C1<T> {
5+
private x;
6+
}
7+
8+
class C2 extends C1<T1> {
9+
y;
10+
}
11+
12+
var c1: C1<T2>;
13+
<C2>c1; // Should succeed (private x originates in the same declaration)

0 commit comments

Comments
 (0)