Skip to content

Commit cb38c95

Browse files
committed
Add a test to make sure types are being checked for privates
1 parent ba57472 commit cb38c95

File tree

5 files changed

+70
-38
lines changed

5 files changed

+70
-38
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4340,7 +4340,7 @@ module ts {
43404340
var widenedType = getWidenedType(exprType, /*supressNoImplicitAnyErrors*/ true);
43414341
if (!(isTypeAssignableTo(targetType, widenedType))) {
43424342
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);
4343-
}
4343+
}
43444344
}
43454345
return targetType;
43464346
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
==== tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3.ts (1 errors) ====
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+
17+
class C3<T> {
18+
private x: T; // This T is the difference between C3 and C1
19+
}
20+
21+
class C4 extends C3<T1> {
22+
y;
23+
}
24+
25+
var c3: C3<T2>;
26+
<C4>c3; // Should fail (private x originates in the same declaration, but different types)
27+
~~~~~~
28+
!!! Neither type 'C3<T2>' nor type 'C4' is assignable to the other:
29+
!!! Property 'y' is missing in type 'C3<T2>'.

tests/baselines/reference/objectTypesIdentityWithPrivates3.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@ class C2 extends C1<T1> {
1111
}
1212

1313
var c1: C1<T2>;
14-
<C2>c1; // Should succeed (private x originates in the same declaration)
14+
<C2>c1; // Should succeed (private x originates in the same declaration)
15+
16+
17+
class C3<T> {
18+
private x: T; // This T is the difference between C3 and C1
19+
}
20+
21+
class C4 extends C3<T1> {
22+
y;
23+
}
24+
25+
var c3: C3<T2>;
26+
<C4>c3; // Should fail (private x originates in the same declaration, but different types)
1527

1628
//// [objectTypesIdentityWithPrivates3.js]
1729
var __extends = this.__extends || function (d, b) {
@@ -34,3 +46,17 @@ var C2 = (function (_super) {
3446
})(C1);
3547
var c1;
3648
c1; // Should succeed (private x originates in the same declaration)
49+
var C3 = (function () {
50+
function C3() {
51+
}
52+
return C3;
53+
})();
54+
var C4 = (function (_super) {
55+
__extends(C4, _super);
56+
function C4() {
57+
_super.apply(this, arguments);
58+
}
59+
return C4;
60+
})(C3);
61+
var c3;
62+
c3; // Should fail (private x originates in the same declaration, but different types)

tests/baselines/reference/objectTypesIdentityWithPrivates3.types

Lines changed: 0 additions & 35 deletions
This file was deleted.

tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,16 @@ class C2 extends C1<T1> {
1010
}
1111

1212
var c1: C1<T2>;
13-
<C2>c1; // Should succeed (private x originates in the same declaration)
13+
<C2>c1; // Should succeed (private x originates in the same declaration)
14+
15+
16+
class C3<T> {
17+
private x: T; // This T is the difference between C3 and C1
18+
}
19+
20+
class C4 extends C3<T1> {
21+
y;
22+
}
23+
24+
var c3: C3<T2>;
25+
<C4>c3; // Should fail (private x originates in the same declaration, but different types)

0 commit comments

Comments
 (0)