Check that private properties originate in the same declaration

This commit is contained in:
Jason Freeman 2014-09-11 18:08:10 -07:00
parent 1eb924f2d6
commit ba574725c2
4 changed files with 90 additions and 4 deletions

View File

@ -2888,10 +2888,12 @@ module ts {
}
if (getDeclarationFlagsFromSymbol(sourceProp) & NodeFlags.Private || getDeclarationFlagsFromSymbol(targetProp) & NodeFlags.Private) {
if (reportErrors) {
reportError(Diagnostics.Private_property_0_cannot_be_reimplemented, symbolToString(targetProp));
if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) {
if (reportErrors) {
reportError(Diagnostics.Private_property_0_cannot_be_reimplemented, symbolToString(targetProp));
}
return false;
}
return false;
}
if (!isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors)) {
if (reportErrors) {
@ -4338,7 +4340,7 @@ module ts {
var widenedType = getWidenedType(exprType, /*supressNoImplicitAnyErrors*/ true);
if (!(isTypeAssignableTo(targetType, widenedType))) {
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);
}
}
}
return targetType;
}

View File

@ -0,0 +1,36 @@
//// [objectTypesIdentityWithPrivates3.ts]
interface T1 { }
interface T2 { z }
class C1<T> {
private x;
}
class C2 extends C1<T1> {
y;
}
var c1: C1<T2>;
<C2>c1; // Should succeed (private x originates in the same declaration)
//// [objectTypesIdentityWithPrivates3.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var C1 = (function () {
function C1() {
}
return C1;
})();
var C2 = (function (_super) {
__extends(C2, _super);
function C2() {
_super.apply(this, arguments);
}
return C2;
})(C1);
var c1;
c1; // Should succeed (private x originates in the same declaration)

View File

@ -0,0 +1,35 @@
=== tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3.ts ===
interface T1 { }
>T1 : T1
interface T2 { z }
>T2 : T2
>z : any
class C1<T> {
>C1 : C1<T>
>T : T
private x;
>x : any
}
class C2 extends C1<T1> {
>C2 : C2
>C1 : C1<T>
>T1 : T1
y;
>y : any
}
var c1: C1<T2>;
>c1 : C1<T2>
>C1 : C1<T>
>T2 : T2
<C2>c1; // Should succeed (private x originates in the same declaration)
><C2>c1 : C2
>C2 : C2
>c1 : C1<T2>

View File

@ -0,0 +1,13 @@
interface T1 { }
interface T2 { z }
class C1<T> {
private x;
}
class C2 extends C1<T1> {
y;
}
var c1: C1<T2>;
<C2>c1; // Should succeed (private x originates in the same declaration)