mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
181 lines
8.7 KiB
TypeScript
181 lines
8.7 KiB
TypeScript
//// [tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts] ////
|
|
|
|
//// [protectedClassPropertyAccessibleWithinSubclass2.ts]
|
|
class Base {
|
|
protected x!: string;
|
|
method() {
|
|
var b: Base = undefined as any;
|
|
var d1: Derived1 = undefined as any;
|
|
var d2: Derived2 = undefined as any;
|
|
var d3: Derived3 = undefined as any;
|
|
var d4: Derived4 = undefined as any;
|
|
|
|
b.x; // OK, accessed within their declaring class
|
|
d1.x; // OK, accessed within their declaring class
|
|
d2.x; // OK, accessed within their declaring class
|
|
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
|
|
d4.x; // OK, accessed within their declaring class
|
|
}
|
|
}
|
|
|
|
class Derived1 extends Base {
|
|
method1() {
|
|
var b: Base = undefined as any;
|
|
var d1: Derived1 = undefined as any;
|
|
var d2: Derived2 = undefined as any;
|
|
var d3: Derived3 = undefined as any;
|
|
var d4: Derived4 = undefined as any;
|
|
|
|
b.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d1.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
|
|
d2.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
|
|
d4.x; // Error, isn't accessed through an instance of the enclosing class
|
|
}
|
|
}
|
|
|
|
class Derived2 extends Base {
|
|
method2() {
|
|
var b: Base = undefined as any;
|
|
var d1: Derived1 = undefined as any;
|
|
var d2: Derived2 = undefined as any;
|
|
var d3: Derived3 = undefined as any;
|
|
var d4: Derived4 = undefined as any;
|
|
|
|
b.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d1.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d2.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
|
|
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
|
|
d4.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class or one of its subclasses
|
|
}
|
|
}
|
|
|
|
class Derived3 extends Derived1 {
|
|
protected x!: string;
|
|
method3() {
|
|
var b: Base = undefined as any;
|
|
var d1: Derived1 = undefined as any;
|
|
var d2: Derived2 = undefined as any;
|
|
var d3: Derived3 = undefined as any;
|
|
var d4: Derived4 = undefined as any;
|
|
|
|
b.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d1.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d2.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d3.x; // OK, accessed within their declaring class
|
|
d4.x; // Error, isn't accessed through an instance of the enclosing class
|
|
}
|
|
}
|
|
|
|
class Derived4 extends Derived2 {
|
|
method4() {
|
|
var b: Base = undefined as any;
|
|
var d1: Derived1 = undefined as any;
|
|
var d2: Derived2 = undefined as any;
|
|
var d3: Derived3 = undefined as any;
|
|
var d4: Derived4 = undefined as any;
|
|
|
|
b.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d1.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d2.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
|
|
d4.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
|
|
}
|
|
}
|
|
|
|
|
|
var b: Base = undefined as any;
|
|
var d1: Derived1 = undefined as any;
|
|
var d2: Derived2 = undefined as any;
|
|
var d3: Derived3 = undefined as any;
|
|
var d4: Derived4 = undefined as any;
|
|
|
|
b.x; // Error, neither within their declaring class nor classes derived from their declaring class
|
|
d1.x; // Error, neither within their declaring class nor classes derived from their declaring class
|
|
d2.x; // Error, neither within their declaring class nor classes derived from their declaring class
|
|
d3.x; // Error, neither within their declaring class nor classes derived from their declaring class
|
|
d4.x; // Error, neither within their declaring class nor classes derived from their declaring class
|
|
|
|
//// [protectedClassPropertyAccessibleWithinSubclass2.js]
|
|
"use strict";
|
|
class Base {
|
|
method() {
|
|
var b = undefined;
|
|
var d1 = undefined;
|
|
var d2 = undefined;
|
|
var d3 = undefined;
|
|
var d4 = undefined;
|
|
b.x; // OK, accessed within their declaring class
|
|
d1.x; // OK, accessed within their declaring class
|
|
d2.x; // OK, accessed within their declaring class
|
|
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
|
|
d4.x; // OK, accessed within their declaring class
|
|
}
|
|
}
|
|
class Derived1 extends Base {
|
|
method1() {
|
|
var b = undefined;
|
|
var d1 = undefined;
|
|
var d2 = undefined;
|
|
var d3 = undefined;
|
|
var d4 = undefined;
|
|
b.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d1.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
|
|
d2.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
|
|
d4.x; // Error, isn't accessed through an instance of the enclosing class
|
|
}
|
|
}
|
|
class Derived2 extends Base {
|
|
method2() {
|
|
var b = undefined;
|
|
var d1 = undefined;
|
|
var d2 = undefined;
|
|
var d3 = undefined;
|
|
var d4 = undefined;
|
|
b.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d1.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d2.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
|
|
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
|
|
d4.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class or one of its subclasses
|
|
}
|
|
}
|
|
class Derived3 extends Derived1 {
|
|
method3() {
|
|
var b = undefined;
|
|
var d1 = undefined;
|
|
var d2 = undefined;
|
|
var d3 = undefined;
|
|
var d4 = undefined;
|
|
b.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d1.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d2.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d3.x; // OK, accessed within their declaring class
|
|
d4.x; // Error, isn't accessed through an instance of the enclosing class
|
|
}
|
|
}
|
|
class Derived4 extends Derived2 {
|
|
method4() {
|
|
var b = undefined;
|
|
var d1 = undefined;
|
|
var d2 = undefined;
|
|
var d3 = undefined;
|
|
var d4 = undefined;
|
|
b.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d1.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d2.x; // Error, isn't accessed through an instance of the enclosing class
|
|
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
|
|
d4.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
|
|
}
|
|
}
|
|
var b = undefined;
|
|
var d1 = undefined;
|
|
var d2 = undefined;
|
|
var d3 = undefined;
|
|
var d4 = undefined;
|
|
b.x; // Error, neither within their declaring class nor classes derived from their declaring class
|
|
d1.x; // Error, neither within their declaring class nor classes derived from their declaring class
|
|
d2.x; // Error, neither within their declaring class nor classes derived from their declaring class
|
|
d3.x; // Error, neither within their declaring class nor classes derived from their declaring class
|
|
d4.x; // Error, neither within their declaring class nor classes derived from their declaring class
|