From e1be0ff23be90f356d00f59bfe366accd7642daa Mon Sep 17 00:00:00 2001 From: AbubakerB Date: Sun, 21 Feb 2016 22:12:31 +0000 Subject: [PATCH] Added more tests and accept baselines --- ...AccessibleWithinNestedSubclass1.errors.txt | 180 ++++++++++++ ...PropertyAccessibleWithinNestedSubclass1.js | 260 ++++++++++++++++++ ...PropertyAccessibleWithinNestedSubclass1.ts | 114 ++++++++ 3 files changed, 554 insertions(+) create mode 100644 tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.errors.txt create mode 100644 tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.js create mode 100644 tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts diff --git a/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.errors.txt b/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.errors.txt new file mode 100644 index 0000000000..ee1fbbdaae --- /dev/null +++ b/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.errors.txt @@ -0,0 +1,180 @@ +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(15,17): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(32,17): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(34,17): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(35,17): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(36,17): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(52,17): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(53,17): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(55,17): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(73,17): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(74,17): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(75,17): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(77,17): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(93,17): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(94,17): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(95,17): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(96,17): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(110,1): error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(111,1): error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(112,1): error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(113,1): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(114,1): error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses. + + +==== tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts (21 errors) ==== + class Base { + protected x: string; + method() { + class A { + methoda() { + var b: Base; + var d1: Derived1; + var d2: Derived2; + var d3: Derived3; + var d4: Derived4; + + 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 + ~~~~ +!!! error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses. + d4.x; // OK, accessed within their declaring class + } + } + } + } + + class Derived1 extends Base { + method1() { + class B { + method1b() { + var b: Base; + var d1: Derived1; + var d2: Derived2; + var d3: Derived3; + var d4: Derived4; + + b.x; // Error, isn't accessed through an instance of the enclosing class + ~~~ +!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'. + 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 + ~~~~ +!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'. + d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses + ~~~~ +!!! error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses. + d4.x; // Error, isn't accessed through an instance of the enclosing class + ~~~~ +!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'. + } + } + } + } + + class Derived2 extends Base { + method2() { + class C { + method2c() { + var b: Base; + var d1: Derived1; + var d2: Derived2; + var d3: Derived3; + var d4: Derived4; + + b.x; // Error, isn't accessed through an instance of the enclosing class + ~~~ +!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. + d1.x; // Error, isn't accessed through an instance of the enclosing class + ~~~~ +!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. + 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 + ~~~~ +!!! error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and 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() { + class D { + method3d() { + var b: Base; + var d1: Derived1; + var d2: Derived2; + var d3: Derived3; + var d4: Derived4; + + b.x; // Error, isn't accessed through an instance of the enclosing class + ~~~ +!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. + d1.x; // Error, isn't accessed through an instance of the enclosing class + ~~~~ +!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. + d2.x; // Error, isn't accessed through an instance of the enclosing class + ~~~~ +!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. + d3.x; // OK, accessed within their declaring class + d4.x; // Error, isn't accessed through an instance of the enclosing class + ~~~~ +!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. + } + } + } + } + + class Derived4 extends Derived2 { + method4() { + class E { + method4e() { + var b: Base; + var d1: Derived1; + var d2: Derived2; + var d3: Derived3; + var d4: Derived4; + + b.x; // Error, isn't accessed through an instance of the enclosing class + ~~~ +!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'. + d1.x; // Error, isn't accessed through an instance of the enclosing class + ~~~~ +!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'. + d2.x; // Error, isn't accessed through an instance of the enclosing class + ~~~~ +!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'. + d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses + ~~~~ +!!! error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and 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; + var d1: Derived1; + var d2: Derived2; + var d3: Derived3; + var d4: Derived4; + + b.x; // Error, neither within their declaring class nor classes derived from their declaring class + ~~~ +!!! error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses. + d1.x; // Error, neither within their declaring class nor classes derived from their declaring class + ~~~~ +!!! error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses. + d2.x; // Error, neither within their declaring class nor classes derived from their declaring class + ~~~~ +!!! error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses. + d3.x; // Error, neither within their declaring class nor classes derived from their declaring class + ~~~~ +!!! error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses. + d4.x; // Error, neither within their declaring class nor classes derived from their declaring class + ~~~~ +!!! error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses. \ No newline at end of file diff --git a/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.js b/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.js new file mode 100644 index 0000000000..02ad29bd31 --- /dev/null +++ b/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.js @@ -0,0 +1,260 @@ +//// [protectedClassPropertyAccessibleWithinNestedSubclass1.ts] +class Base { + protected x: string; + method() { + class A { + methoda() { + var b: Base; + var d1: Derived1; + var d2: Derived2; + var d3: Derived3; + var d4: Derived4; + + 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() { + class B { + method1b() { + var b: Base; + var d1: Derived1; + var d2: Derived2; + var d3: Derived3; + var d4: Derived4; + + 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() { + class C { + method2c() { + var b: Base; + var d1: Derived1; + var d2: Derived2; + var d3: Derived3; + var d4: Derived4; + + 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() { + class D { + method3d() { + var b: Base; + var d1: Derived1; + var d2: Derived2; + var d3: Derived3; + var d4: Derived4; + + 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() { + class E { + method4e() { + var b: Base; + var d1: Derived1; + var d2: Derived2; + var d3: Derived3; + var d4: Derived4; + + 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; +var d1: Derived1; +var d2: Derived2; +var d3: Derived3; +var d4: Derived4; + +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 + +//// [protectedClassPropertyAccessibleWithinNestedSubclass1.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Base = (function () { + function Base() { + } + Base.prototype.method = function () { + var A = (function () { + function A() { + } + A.prototype.methoda = function () { + var b; + var d1; + var d2; + var d3; + var d4; + 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 + }; + return A; + }()); + }; + return Base; +}()); +var Derived1 = (function (_super) { + __extends(Derived1, _super); + function Derived1() { + _super.apply(this, arguments); + } + Derived1.prototype.method1 = function () { + var B = (function () { + function B() { + } + B.prototype.method1b = function () { + var b; + var d1; + var d2; + var d3; + var d4; + 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 + }; + return B; + }()); + }; + return Derived1; +}(Base)); +var Derived2 = (function (_super) { + __extends(Derived2, _super); + function Derived2() { + _super.apply(this, arguments); + } + Derived2.prototype.method2 = function () { + var C = (function () { + function C() { + } + C.prototype.method2c = function () { + var b; + var d1; + var d2; + var d3; + var d4; + 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 + }; + return C; + }()); + }; + return Derived2; +}(Base)); +var Derived3 = (function (_super) { + __extends(Derived3, _super); + function Derived3() { + _super.apply(this, arguments); + } + Derived3.prototype.method3 = function () { + var D = (function () { + function D() { + } + D.prototype.method3d = function () { + var b; + var d1; + var d2; + var d3; + var d4; + 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 + }; + return D; + }()); + }; + return Derived3; +}(Derived1)); +var Derived4 = (function (_super) { + __extends(Derived4, _super); + function Derived4() { + _super.apply(this, arguments); + } + Derived4.prototype.method4 = function () { + var E = (function () { + function E() { + } + E.prototype.method4e = function () { + var b; + var d1; + var d2; + var d3; + var d4; + 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 + }; + return E; + }()); + }; + return Derived4; +}(Derived2)); +var b; +var d1; +var d2; +var d3; +var d4; +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 diff --git a/tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts b/tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts new file mode 100644 index 0000000000..1128da7079 --- /dev/null +++ b/tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts @@ -0,0 +1,114 @@ +class Base { + protected x: string; + method() { + class A { + methoda() { + var b: Base; + var d1: Derived1; + var d2: Derived2; + var d3: Derived3; + var d4: Derived4; + + 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() { + class B { + method1b() { + var b: Base; + var d1: Derived1; + var d2: Derived2; + var d3: Derived3; + var d4: Derived4; + + 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() { + class C { + method2c() { + var b: Base; + var d1: Derived1; + var d2: Derived2; + var d3: Derived3; + var d4: Derived4; + + 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() { + class D { + method3d() { + var b: Base; + var d1: Derived1; + var d2: Derived2; + var d3: Derived3; + var d4: Derived4; + + 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() { + class E { + method4e() { + var b: Base; + var d1: Derived1; + var d2: Derived2; + var d3: Derived3; + var d4: Derived4; + + 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; +var d1: Derived1; +var d2: Derived2; +var d3: Derived3; +var d4: Derived4; + +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 \ No newline at end of file