267 lines
6.3 KiB
TypeScript
267 lines
6.3 KiB
TypeScript
//// [mixinAccessModifiers.ts]
|
|
|
|
type Constructable = new (...args: any[]) => object;
|
|
|
|
class Private {
|
|
constructor (...args: any[]) {}
|
|
private p: string;
|
|
}
|
|
|
|
class Private2 {
|
|
constructor (...args: any[]) {}
|
|
private p: string;
|
|
}
|
|
|
|
class Protected {
|
|
constructor (...args: any[]) {}
|
|
protected p: string;
|
|
protected static s: string;
|
|
}
|
|
|
|
class Protected2 {
|
|
constructor (...args: any[]) {}
|
|
protected p: string;
|
|
protected static s: string;
|
|
}
|
|
|
|
class Public {
|
|
constructor (...args: any[]) {}
|
|
public p: string;
|
|
public static s: string;
|
|
}
|
|
|
|
class Public2 {
|
|
constructor (...args: any[]) {}
|
|
public p: string;
|
|
public static s: string;
|
|
}
|
|
|
|
function f1(x: Private & Private2) {
|
|
x.p; // Error, private constituent makes property inaccessible
|
|
}
|
|
|
|
function f2(x: Private & Protected) {
|
|
x.p; // Error, private constituent makes property inaccessible
|
|
}
|
|
|
|
function f3(x: Private & Public) {
|
|
x.p; // Error, private constituent makes property inaccessible
|
|
}
|
|
|
|
function f4(x: Protected & Protected2) {
|
|
x.p; // Error, protected when all constituents are protected
|
|
}
|
|
|
|
function f5(x: Protected & Public) {
|
|
x.p; // Ok, public if any constituent is public
|
|
}
|
|
|
|
function f6(x: Public & Public2) {
|
|
x.p; // Ok, public if any constituent is public
|
|
}
|
|
|
|
declare function Mix<T, U>(c1: T, c2: U): T & U;
|
|
|
|
// Can't derive from type with inaccessible properties
|
|
|
|
class C1 extends Mix(Private, Private2) {}
|
|
class C2 extends Mix(Private, Protected) {}
|
|
class C3 extends Mix(Private, Public) {}
|
|
|
|
class C4 extends Mix(Protected, Protected2) {
|
|
f(c4: C4, c5: C5, c6: C6) {
|
|
c4.p;
|
|
c5.p;
|
|
c6.p;
|
|
}
|
|
static g() {
|
|
C4.s;
|
|
C5.s;
|
|
C6.s
|
|
}
|
|
}
|
|
|
|
class C5 extends Mix(Protected, Public) {
|
|
f(c4: C4, c5: C5, c6: C6) {
|
|
c4.p; // Error, not in class deriving from Protected2
|
|
c5.p;
|
|
c6.p;
|
|
}
|
|
static g() {
|
|
C4.s; // Error, not in class deriving from Protected2
|
|
C5.s;
|
|
C6.s
|
|
}
|
|
}
|
|
|
|
class C6 extends Mix(Public, Public2) {
|
|
f(c4: C4, c5: C5, c6: C6) {
|
|
c4.p; // Error, not in class deriving from Protected2
|
|
c5.p;
|
|
c6.p;
|
|
}
|
|
static g() {
|
|
C4.s; // Error, not in class deriving from Protected2
|
|
C5.s;
|
|
C6.s
|
|
}
|
|
}
|
|
|
|
|
|
//// [mixinAccessModifiers.js]
|
|
var __extends = (this && this.__extends) || (function () {
|
|
var extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
return function (d, b) {
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
var Private = (function () {
|
|
function Private() {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
}
|
|
return Private;
|
|
}());
|
|
var Private2 = (function () {
|
|
function Private2() {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
}
|
|
return Private2;
|
|
}());
|
|
var Protected = (function () {
|
|
function Protected() {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
}
|
|
return Protected;
|
|
}());
|
|
var Protected2 = (function () {
|
|
function Protected2() {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
}
|
|
return Protected2;
|
|
}());
|
|
var Public = (function () {
|
|
function Public() {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
}
|
|
return Public;
|
|
}());
|
|
var Public2 = (function () {
|
|
function Public2() {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
}
|
|
return Public2;
|
|
}());
|
|
function f1(x) {
|
|
x.p; // Error, private constituent makes property inaccessible
|
|
}
|
|
function f2(x) {
|
|
x.p; // Error, private constituent makes property inaccessible
|
|
}
|
|
function f3(x) {
|
|
x.p; // Error, private constituent makes property inaccessible
|
|
}
|
|
function f4(x) {
|
|
x.p; // Error, protected when all constituents are protected
|
|
}
|
|
function f5(x) {
|
|
x.p; // Ok, public if any constituent is public
|
|
}
|
|
function f6(x) {
|
|
x.p; // Ok, public if any constituent is public
|
|
}
|
|
// Can't derive from type with inaccessible properties
|
|
var C1 = (function (_super) {
|
|
__extends(C1, _super);
|
|
function C1() {
|
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
}
|
|
return C1;
|
|
}(Mix(Private, Private2)));
|
|
var C2 = (function (_super) {
|
|
__extends(C2, _super);
|
|
function C2() {
|
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
}
|
|
return C2;
|
|
}(Mix(Private, Protected)));
|
|
var C3 = (function (_super) {
|
|
__extends(C3, _super);
|
|
function C3() {
|
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
}
|
|
return C3;
|
|
}(Mix(Private, Public)));
|
|
var C4 = (function (_super) {
|
|
__extends(C4, _super);
|
|
function C4() {
|
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
}
|
|
C4.prototype.f = function (c4, c5, c6) {
|
|
c4.p;
|
|
c5.p;
|
|
c6.p;
|
|
};
|
|
C4.g = function () {
|
|
C4.s;
|
|
C5.s;
|
|
C6.s;
|
|
};
|
|
return C4;
|
|
}(Mix(Protected, Protected2)));
|
|
var C5 = (function (_super) {
|
|
__extends(C5, _super);
|
|
function C5() {
|
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
}
|
|
C5.prototype.f = function (c4, c5, c6) {
|
|
c4.p; // Error, not in class deriving from Protected2
|
|
c5.p;
|
|
c6.p;
|
|
};
|
|
C5.g = function () {
|
|
C4.s; // Error, not in class deriving from Protected2
|
|
C5.s;
|
|
C6.s;
|
|
};
|
|
return C5;
|
|
}(Mix(Protected, Public)));
|
|
var C6 = (function (_super) {
|
|
__extends(C6, _super);
|
|
function C6() {
|
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
}
|
|
C6.prototype.f = function (c4, c5, c6) {
|
|
c4.p; // Error, not in class deriving from Protected2
|
|
c5.p;
|
|
c6.p;
|
|
};
|
|
C6.g = function () {
|
|
C4.s; // Error, not in class deriving from Protected2
|
|
C5.s;
|
|
C6.s;
|
|
};
|
|
return C6;
|
|
}(Mix(Public, Public2)));
|