Added and updated tests for constructor visibility

This commit is contained in:
AbubakerB 2016-02-03 22:48:33 +00:00
parent f869b41f14
commit c351ffcc75
31 changed files with 843 additions and 110 deletions

View File

@ -1,9 +0,0 @@
tests/cases/conformance/parser/ecmascript5/Protected/Protected3.ts(2,3): error TS1089: 'protected' modifier cannot appear on a constructor declaration.
==== tests/cases/conformance/parser/ecmascript5/Protected/Protected3.ts (1 errors) ====
class C {
protected constructor() { }
~~~~~~~~~
!!! error TS1089: 'protected' modifier cannot appear on a constructor declaration.
}

View File

@ -0,0 +1,6 @@
=== tests/cases/conformance/parser/ecmascript5/Protected/Protected3.ts ===
class C {
>C : Symbol(C, Decl(Protected3.ts, 0, 0))
protected constructor() { }
}

View File

@ -0,0 +1,6 @@
=== tests/cases/conformance/parser/ecmascript5/Protected/Protected3.ts ===
class C {
>C : C
protected constructor() { }
}

View File

@ -1,29 +1,30 @@
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(6,5): error TS1089: 'private' modifier cannot appear on a constructor declaration.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(10,5): error TS1089: 'protected' modifier cannot appear on a constructor declaration.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(23,9): error TS1089: 'private' modifier cannot appear on a constructor declaration.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(27,9): error TS1089: 'protected' modifier cannot appear on a constructor declaration.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(15,9): error TS2673: Constructor of type '(x: number): D' is private and only accessible within class 'D'.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(16,9): error TS2674: Constructor of type '(x: number): E' is protected and only accessible within class 'E'.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(32,13): error TS2673: Constructor of type '<T>(x: T): D<T>' is private and only accessible within class 'D<T>'.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(33,13): error TS2674: Constructor of type '<T>(x: T): E<T>' is protected and only accessible within class 'E<T>'.
==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts (4 errors) ====
class C {
public constructor(public x: number) { }
}
class D {
private constructor(public x: number) { } // error
~~~~~~~
!!! error TS1089: 'private' modifier cannot appear on a constructor declaration.
private constructor(public x: number) { }
}
class E {
protected constructor(public x: number) { } // error
~~~~~~~~~
!!! error TS1089: 'protected' modifier cannot appear on a constructor declaration.
protected constructor(public x: number) { }
}
var c = new C(1);
var d = new D(1);
var e = new E(1);
var d = new D(1); // error
~~~~~~~~
!!! error TS2673: Constructor of type '(x: number): D' is private and only accessible within class 'D'.
var e = new E(1); // error
~~~~~~~~
!!! error TS2674: Constructor of type '(x: number): E' is protected and only accessible within class 'E'.
module Generic {
class C<T> {
@ -31,19 +32,19 @@ tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessib
}
class D<T> {
private constructor(public x: T) { } // error
~~~~~~~
!!! error TS1089: 'private' modifier cannot appear on a constructor declaration.
private constructor(public x: T) { }
}
class E<T> {
protected constructor(public x: T) { } // error
~~~~~~~~~
!!! error TS1089: 'protected' modifier cannot appear on a constructor declaration.
protected constructor(public x: T) { }
}
var c = new C(1);
var d = new D(1);
var e = new E(1);
var d = new D(1); // error
~~~~~~~~
!!! error TS2673: Constructor of type '<T>(x: T): D<T>' is private and only accessible within class 'D<T>'.
var e = new E(1); // error
~~~~~~~~
!!! error TS2674: Constructor of type '<T>(x: T): E<T>' is protected and only accessible within class 'E<T>'.
}

View File

@ -1,19 +1,20 @@
//// [classConstructorAccessibility.ts]
class C {
public constructor(public x: number) { }
}
class D {
private constructor(public x: number) { } // error
private constructor(public x: number) { }
}
class E {
protected constructor(public x: number) { } // error
protected constructor(public x: number) { }
}
var c = new C(1);
var d = new D(1);
var e = new E(1);
var d = new D(1); // error
var e = new E(1); // error
module Generic {
class C<T> {
@ -21,16 +22,16 @@ module Generic {
}
class D<T> {
private constructor(public x: T) { } // error
private constructor(public x: T) { }
}
class E<T> {
protected constructor(public x: T) { } // error
protected constructor(public x: T) { }
}
var c = new C(1);
var d = new D(1);
var e = new E(1);
var d = new D(1); // error
var e = new E(1); // error
}
@ -44,18 +45,18 @@ var C = (function () {
var D = (function () {
function D(x) {
this.x = x;
} // error
}
return D;
}());
var E = (function () {
function E(x) {
this.x = x;
} // error
}
return E;
}());
var c = new C(1);
var d = new D(1);
var e = new E(1);
var d = new D(1); // error
var e = new E(1); // error
var Generic;
(function (Generic) {
var C = (function () {
@ -67,16 +68,36 @@ var Generic;
var D = (function () {
function D(x) {
this.x = x;
} // error
}
return D;
}());
var E = (function () {
function E(x) {
this.x = x;
} // error
}
return E;
}());
var c = new C(1);
var d = new D(1);
var e = new E(1);
var d = new D(1); // error
var e = new E(1); // error
})(Generic || (Generic = {}));
//// [classConstructorAccessibility.d.ts]
declare class C {
x: number;
constructor(x: number);
}
declare class D {
x: number;
constructor(x);
}
declare class E {
x: number;
constructor(x: number);
}
declare var c: C;
declare var d: any;
declare var e: any;
declare module Generic {
}

View File

@ -0,0 +1,59 @@
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(26,28): error TS2674: Constructor of type '(x: number): BaseB' is protected and only accessible within class 'BaseB'.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(29,24): error TS2675: Cannot extend private class 'BaseC'.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(32,28): error TS2673: Constructor of type '(x: number): BaseC' is private and only accessible within class 'BaseC'.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(36,10): error TS2674: Constructor of type '(x: number): BaseB' is protected and only accessible within class 'BaseB'.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(37,10): error TS2673: Constructor of type '(x: number): BaseC' is private and only accessible within class 'BaseC'.
==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts (5 errors) ====
class BaseA {
public constructor(public x: number) { }
createInstance() { new BaseA(1); }
}
class BaseB {
protected constructor(public x: number) { }
createInstance() { new BaseB(1); }
}
class BaseC {
private constructor(public x: number) { }
createInstance() { new BaseC(1); }
}
class DerivedA extends BaseA {
constructor(public x: number) { super(x); }
createInstance() { new DerivedA(1); }
createBaseInstance() { new BaseA(1); }
}
class DerivedB extends BaseB {
constructor(public x: number) { super(x); }
createInstance() { new DerivedB(1); }
createBaseInstance() { new BaseB(1); } // error
~~~~~~~~~~~~
!!! error TS2674: Constructor of type '(x: number): BaseB' is protected and only accessible within class 'BaseB'.
}
class DerivedC extends BaseC { // error
~~~~~
!!! error TS2675: Cannot extend private class 'BaseC'.
constructor(public x: number) { super(x); }
createInstance() { new DerivedC(1); }
createBaseInstance() { new BaseC(1); } // error
~~~~~~~~~~~~
!!! error TS2673: Constructor of type '(x: number): BaseC' is private and only accessible within class 'BaseC'.
}
var ba = new BaseA(1);
var bb = new BaseB(1); // error
~~~~~~~~~~~~
!!! error TS2674: Constructor of type '(x: number): BaseB' is protected and only accessible within class 'BaseB'.
var bc = new BaseC(1); // error
~~~~~~~~~~~~
!!! error TS2673: Constructor of type '(x: number): BaseC' is private and only accessible within class 'BaseC'.
var da = new DerivedA(1);
var db = new DerivedB(1);
var dc = new DerivedC(1);

View File

@ -0,0 +1,148 @@
//// [classConstructorAccessibility2.ts]
class BaseA {
public constructor(public x: number) { }
createInstance() { new BaseA(1); }
}
class BaseB {
protected constructor(public x: number) { }
createInstance() { new BaseB(1); }
}
class BaseC {
private constructor(public x: number) { }
createInstance() { new BaseC(1); }
}
class DerivedA extends BaseA {
constructor(public x: number) { super(x); }
createInstance() { new DerivedA(1); }
createBaseInstance() { new BaseA(1); }
}
class DerivedB extends BaseB {
constructor(public x: number) { super(x); }
createInstance() { new DerivedB(1); }
createBaseInstance() { new BaseB(1); } // error
}
class DerivedC extends BaseC { // error
constructor(public x: number) { super(x); }
createInstance() { new DerivedC(1); }
createBaseInstance() { new BaseC(1); } // error
}
var ba = new BaseA(1);
var bb = new BaseB(1); // error
var bc = new BaseC(1); // error
var da = new DerivedA(1);
var db = new DerivedB(1);
var dc = new DerivedC(1);
//// [classConstructorAccessibility2.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 BaseA = (function () {
function BaseA(x) {
this.x = x;
}
BaseA.prototype.createInstance = function () { new BaseA(1); };
return BaseA;
}());
var BaseB = (function () {
function BaseB(x) {
this.x = x;
}
BaseB.prototype.createInstance = function () { new BaseB(1); };
return BaseB;
}());
var BaseC = (function () {
function BaseC(x) {
this.x = x;
}
BaseC.prototype.createInstance = function () { new BaseC(1); };
return BaseC;
}());
var DerivedA = (function (_super) {
__extends(DerivedA, _super);
function DerivedA(x) {
_super.call(this, x);
this.x = x;
}
DerivedA.prototype.createInstance = function () { new DerivedA(1); };
DerivedA.prototype.createBaseInstance = function () { new BaseA(1); };
return DerivedA;
}(BaseA));
var DerivedB = (function (_super) {
__extends(DerivedB, _super);
function DerivedB(x) {
_super.call(this, x);
this.x = x;
}
DerivedB.prototype.createInstance = function () { new DerivedB(1); };
DerivedB.prototype.createBaseInstance = function () { new BaseB(1); }; // error
return DerivedB;
}(BaseB));
var DerivedC = (function (_super) {
__extends(DerivedC, _super);
function DerivedC(x) {
_super.call(this, x);
this.x = x;
}
DerivedC.prototype.createInstance = function () { new DerivedC(1); };
DerivedC.prototype.createBaseInstance = function () { new BaseC(1); }; // error
return DerivedC;
}(BaseC));
var ba = new BaseA(1);
var bb = new BaseB(1); // error
var bc = new BaseC(1); // error
var da = new DerivedA(1);
var db = new DerivedB(1);
var dc = new DerivedC(1);
//// [classConstructorAccessibility2.d.ts]
declare class BaseA {
x: number;
constructor(x: number);
createInstance(): void;
}
declare class BaseB {
x: number;
constructor(x: number);
createInstance(): void;
}
declare class BaseC {
x: number;
constructor(x);
createInstance(): void;
}
declare class DerivedA extends BaseA {
x: number;
constructor(x: number);
createInstance(): void;
createBaseInstance(): void;
}
declare class DerivedB extends BaseB {
x: number;
constructor(x: number);
createInstance(): void;
createBaseInstance(): void;
}
declare class DerivedC extends BaseC {
x: number;
constructor(x: number);
createInstance(): void;
createBaseInstance(): void;
}
declare var ba: BaseA;
declare var bb: any;
declare var bc: any;
declare var da: DerivedA;
declare var db: DerivedB;
declare var dc: DerivedC;

View File

@ -0,0 +1,77 @@
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(21,1): error TS2322: Type 'typeof Baz' is not assignable to type 'typeof Foo'.
Cannot assign a 'protected' constructor type to a 'public' constructor type.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(22,1): error TS2322: Type 'typeof Qux' is not assignable to type 'typeof Foo'.
Cannot assign a 'private' constructor type to a 'public' constructor type.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(26,1): error TS2322: Type 'typeof Foo' is not assignable to type 'typeof Baz'.
Cannot assign a 'public' constructor type to a 'protected' constructor type.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(27,1): error TS2322: Type 'typeof Bar' is not assignable to type 'typeof Baz'.
Cannot assign a 'public' constructor type to a 'protected' constructor type.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(28,1): error TS2322: Type 'typeof Qux' is not assignable to type 'typeof Baz'.
Cannot assign a 'private' constructor type to a 'protected' constructor type.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(32,1): error TS2322: Type 'typeof Foo' is not assignable to type 'typeof Qux'.
Cannot assign a 'public' constructor type to a 'private' constructor type.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(33,1): error TS2322: Type 'typeof Bar' is not assignable to type 'typeof Qux'.
Cannot assign a 'public' constructor type to a 'private' constructor type.
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(34,1): error TS2322: Type 'typeof Baz' is not assignable to type 'typeof Qux'.
Cannot assign a 'protected' constructor type to a 'private' constructor type.
==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts (8 errors) ====
class Foo {
constructor(public x: number) { }
}
class Bar {
public constructor(public x: number) { }
}
class Baz {
protected constructor(public x: number) { }
}
class Qux {
private constructor(public x: number) { }
}
// b is public
let a = Foo;
a = Bar;
a = Baz; // error Baz is protected
~
!!! error TS2322: Type 'typeof Baz' is not assignable to type 'typeof Foo'.
!!! error TS2322: Cannot assign a 'protected' constructor type to a 'public' constructor type.
a = Qux; // error Qux is private
~
!!! error TS2322: Type 'typeof Qux' is not assignable to type 'typeof Foo'.
!!! error TS2322: Cannot assign a 'private' constructor type to a 'public' constructor type.
// b is protected
let b = Baz;
b = Foo; // error Foo is public
~
!!! error TS2322: Type 'typeof Foo' is not assignable to type 'typeof Baz'.
!!! error TS2322: Cannot assign a 'public' constructor type to a 'protected' constructor type.
b = Bar; // error Baz is public
~
!!! error TS2322: Type 'typeof Bar' is not assignable to type 'typeof Baz'.
!!! error TS2322: Cannot assign a 'public' constructor type to a 'protected' constructor type.
b = Qux; // error Qux is private
~
!!! error TS2322: Type 'typeof Qux' is not assignable to type 'typeof Baz'.
!!! error TS2322: Cannot assign a 'private' constructor type to a 'protected' constructor type.
// c is private
let c = Qux;
c = Foo; // error Foo is public
~
!!! error TS2322: Type 'typeof Foo' is not assignable to type 'typeof Qux'.
!!! error TS2322: Cannot assign a 'public' constructor type to a 'private' constructor type.
c = Bar; // error Bar is public
~
!!! error TS2322: Type 'typeof Bar' is not assignable to type 'typeof Qux'.
!!! error TS2322: Cannot assign a 'public' constructor type to a 'private' constructor type.
c = Baz; // error Baz is protected
~
!!! error TS2322: Type 'typeof Baz' is not assignable to type 'typeof Qux'.
!!! error TS2322: Cannot assign a 'protected' constructor type to a 'private' constructor type.

View File

@ -0,0 +1,98 @@
//// [classConstructorAccessibility3.ts]
class Foo {
constructor(public x: number) { }
}
class Bar {
public constructor(public x: number) { }
}
class Baz {
protected constructor(public x: number) { }
}
class Qux {
private constructor(public x: number) { }
}
// b is public
let a = Foo;
a = Bar;
a = Baz; // error Baz is protected
a = Qux; // error Qux is private
// b is protected
let b = Baz;
b = Foo; // error Foo is public
b = Bar; // error Baz is public
b = Qux; // error Qux is private
// c is private
let c = Qux;
c = Foo; // error Foo is public
c = Bar; // error Bar is public
c = Baz; // error Baz is protected
//// [classConstructorAccessibility3.js]
var Foo = (function () {
function Foo(x) {
this.x = x;
}
return Foo;
}());
var Bar = (function () {
function Bar(x) {
this.x = x;
}
return Bar;
}());
var Baz = (function () {
function Baz(x) {
this.x = x;
}
return Baz;
}());
var Qux = (function () {
function Qux(x) {
this.x = x;
}
return Qux;
}());
// b is public
var a = Foo;
a = Bar;
a = Baz; // error Baz is protected
a = Qux; // error Qux is private
// b is protected
var b = Baz;
b = Foo; // error Foo is public
b = Bar; // error Baz is public
b = Qux; // error Qux is private
// c is private
var c = Qux;
c = Foo; // error Foo is public
c = Bar; // error Bar is public
c = Baz; // error Baz is protected
//// [classConstructorAccessibility3.d.ts]
declare class Foo {
x: number;
constructor(x: number);
}
declare class Bar {
x: number;
constructor(x: number);
}
declare class Baz {
x: number;
constructor(x: number);
}
declare class Qux {
x: number;
constructor(x);
}
declare let a: typeof Foo;
declare let b: typeof Baz;
declare let c: typeof Qux;

View File

@ -0,0 +1,45 @@
tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts(3,2): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts(4,2): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts(12,2): error TS2385: Overload signatures must all be public, private or protected.
==== tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts (3 errors) ====
class A {
public constructor(a: boolean) // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2385: Overload signatures must all be public, private or protected.
protected constructor(a: number) // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2385: Overload signatures must all be public, private or protected.
private constructor(a: string)
private constructor() {
}
}
class B {
protected constructor(a: number) // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2385: Overload signatures must all be public, private or protected.
constructor(a: string)
constructor() {
}
}
class C {
protected constructor(a: number)
protected constructor(a: string)
protected constructor() {
}
}
class D {
constructor(a: number)
constructor(a: string)
public constructor() {
}
}

View File

@ -0,0 +1,76 @@
//// [classConstructorOverloadsAccessibility.ts]
class A {
public constructor(a: boolean) // error
protected constructor(a: number) // error
private constructor(a: string)
private constructor() {
}
}
class B {
protected constructor(a: number) // error
constructor(a: string)
constructor() {
}
}
class C {
protected constructor(a: number)
protected constructor(a: string)
protected constructor() {
}
}
class D {
constructor(a: number)
constructor(a: string)
public constructor() {
}
}
//// [classConstructorOverloadsAccessibility.js]
var A = (function () {
function A() {
}
return A;
}());
var B = (function () {
function B() {
}
return B;
}());
var C = (function () {
function C() {
}
return C;
}());
var D = (function () {
function D() {
}
return D;
}());
//// [classConstructorOverloadsAccessibility.d.ts]
declare class A {
constructor(a: boolean);
constructor(a: number);
constructor(a);
}
declare class B {
constructor(a: number);
constructor(a: string);
}
declare class C {
constructor(a: number);
constructor(a: string);
}
declare class D {
constructor(a: number);
constructor(a: string);
}

View File

@ -1,10 +1,9 @@
tests/cases/compiler/implicitAnyInAmbientDeclaration.ts(3,9): error TS7008: Member 'publicMember' implicitly has an 'any' type.
tests/cases/compiler/implicitAnyInAmbientDeclaration.ts(6,16): error TS7010: 'publicFunction', which lacks return-type annotation, implicitly has an 'any' return type.
tests/cases/compiler/implicitAnyInAmbientDeclaration.ts(6,31): error TS7006: Parameter 'x' implicitly has an 'any' type.
tests/cases/compiler/implicitAnyInAmbientDeclaration.ts(8,9): error TS1089: 'private' modifier cannot appear on a constructor declaration.
==== tests/cases/compiler/implicitAnyInAmbientDeclaration.ts (4 errors) ====
==== tests/cases/compiler/implicitAnyInAmbientDeclaration.ts (3 errors) ====
module Test {
declare class C {
public publicMember; // this should be an error
@ -19,7 +18,5 @@ tests/cases/compiler/implicitAnyInAmbientDeclaration.ts(8,9): error TS1089: 'pri
!!! error TS7006: Parameter 'x' implicitly has an 'any' type.
private privateFunction(privateParam); // this should not be an error
private constructor(privateParam);
~~~~~~~
!!! error TS1089: 'private' modifier cannot appear on a constructor declaration.
}
}

View File

@ -4,11 +4,10 @@ tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(2,13): error TS7005:
tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(4,5): error TS7008: Member 'publicMember' implicitly has an 'any' type.
tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(7,12): error TS7010: 'publicFunction', which lacks return-type annotation, implicitly has an 'any' return type.
tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(7,27): error TS7006: Parameter 'x' implicitly has an 'any' type.
tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(9,5): error TS1089: 'private' modifier cannot appear on a constructor declaration.
tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(13,24): error TS7006: Parameter 'publicConsParam' implicitly has an 'any' type.
==== tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts (8 errors) ====
==== tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts (7 errors) ====
declare function foo(x); // this should be an error
~~~
!!! error TS7010: 'foo', which lacks return-type annotation, implicitly has an 'any' return type.
@ -30,8 +29,6 @@ tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(13,24): error TS7006:
!!! error TS7006: Parameter 'x' implicitly has an 'any' type.
private privateFunction(privateParam); // this should not be an error
private constructor(privateParam); // this should not be an error
~~~~~~~
!!! error TS1089: 'private' modifier cannot appear on a constructor declaration.
}
declare class D {

View File

@ -1,9 +0,0 @@
tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration5.ts(2,3): error TS1089: 'private' modifier cannot appear on a constructor declaration.
==== tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration5.ts (1 errors) ====
class C {
private constructor() { }
~~~~~~~
!!! error TS1089: 'private' modifier cannot appear on a constructor declaration.
}

View File

@ -0,0 +1,6 @@
=== tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration5.ts ===
class C {
>C : Symbol(C, Decl(parserConstructorDeclaration5.ts, 0, 0))
private constructor() { }
}

View File

@ -0,0 +1,6 @@
=== tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration5.ts ===
class C {
>C : C
private constructor() { }
}

View File

@ -8,16 +8,15 @@ tests/cases/compiler/protectedMembers.ts(48,1): error TS2445: Property 'sx' is p
tests/cases/compiler/protectedMembers.ts(49,1): error TS2445: Property 'sf' is protected and only accessible within class 'C2' and its subclasses.
tests/cases/compiler/protectedMembers.ts(68,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'C'.
tests/cases/compiler/protectedMembers.ts(69,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'C'.
tests/cases/compiler/protectedMembers.ts(86,5): error TS1089: 'protected' modifier cannot appear on a constructor declaration.
tests/cases/compiler/protectedMembers.ts(98,1): error TS2322: Type 'B1' is not assignable to type 'A1'.
tests/cases/compiler/protectedMembers.ts(97,1): error TS2322: Type 'B1' is not assignable to type 'A1'.
Property 'x' is protected but type 'B1' is not a class derived from 'A1'.
tests/cases/compiler/protectedMembers.ts(99,1): error TS2322: Type 'A1' is not assignable to type 'B1'.
tests/cases/compiler/protectedMembers.ts(98,1): error TS2322: Type 'A1' is not assignable to type 'B1'.
Property 'x' is protected in type 'A1' but public in type 'B1'.
tests/cases/compiler/protectedMembers.ts(112,7): error TS2415: Class 'B3' incorrectly extends base class 'A3'.
tests/cases/compiler/protectedMembers.ts(111,7): error TS2415: Class 'B3' incorrectly extends base class 'A3'.
Property 'x' is protected in type 'B3' but public in type 'A3'.
==== tests/cases/compiler/protectedMembers.ts (14 errors) ====
==== tests/cases/compiler/protectedMembers.ts (13 errors) ====
// Class with protected members
class C1 {
protected x: number;
@ -122,10 +121,7 @@ tests/cases/compiler/protectedMembers.ts(112,7): error TS2415: Class 'B3' incorr
}
class CC {
// Error, constructor cannot be protected
protected constructor() {
~~~~~~~~~
!!! error TS1089: 'protected' modifier cannot appear on a constructor declaration.
}
}

View File

@ -83,7 +83,6 @@ interface E extends C {
}
class CC {
// Error, constructor cannot be protected
protected constructor() {
}
}
@ -214,7 +213,6 @@ var D = (function (_super) {
return D;
}(C));
var CC = (function () {
// Error, constructor cannot be protected
function CC() {
}
return CC;

View File

@ -1,36 +1,24 @@
tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(4,5): error TS1089: 'private' modifier cannot appear on a constructor declaration.
tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(8,5): error TS2322: Type 'Function' is not assignable to type '() => void'.
Type 'Function' provides no match for the signature '(): void'
tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(11,5): error TS1089: 'private' modifier cannot appear on a constructor declaration.
tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(12,5): error TS1089: 'private' modifier cannot appear on a constructor declaration.
tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(15,10): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(6,9): error TS2673: Constructor of type '(): C' is private and only accessible within class 'C'.
tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(14,10): error TS2673: Constructor of type '(x: number): C2' is private and only accessible within class 'C2'.
==== tests/cases/conformance/types/members/typesWithPrivateConstructor.ts (5 errors) ====
// private constructors are not allowed
==== tests/cases/conformance/types/members/typesWithPrivateConstructor.ts (2 errors) ====
class C {
private constructor() { }
~~~~~~~
!!! error TS1089: 'private' modifier cannot appear on a constructor declaration.
}
var c = new C();
var c = new C(); // error C is private
~~~~~~~
!!! error TS2673: Constructor of type '(): C' is private and only accessible within class 'C'.
var r: () => void = c.constructor;
~
!!! error TS2322: Type 'Function' is not assignable to type '() => void'.
!!! error TS2322: Type 'Function' provides no match for the signature '(): void'
class C2 {
private constructor(x: number);
~~~~~~~
!!! error TS1089: 'private' modifier cannot appear on a constructor declaration.
private constructor(x: any) { }
~~~~~~~
!!! error TS1089: 'private' modifier cannot appear on a constructor declaration.
}
var c2 = new C2();
var c2 = new C2(); // error C2 is private
~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
!!! error TS2673: Constructor of type '(x: number): C2' is private and only accessible within class 'C2'.
var r2: (x: number) => void = c2.constructor;

View File

@ -1,11 +1,10 @@
//// [typesWithPrivateConstructor.ts]
// private constructors are not allowed
class C {
private constructor() { }
}
var c = new C();
var c = new C(); // error C is private
var r: () => void = c.constructor;
class C2 {
@ -13,22 +12,34 @@ class C2 {
private constructor(x: any) { }
}
var c2 = new C2();
var c2 = new C2(); // error C2 is private
var r2: (x: number) => void = c2.constructor;
//// [typesWithPrivateConstructor.js]
// private constructors are not allowed
var C = (function () {
function C() {
}
return C;
}());
var c = new C();
var c = new C(); // error C is private
var r = c.constructor;
var C2 = (function () {
function C2(x) {
}
return C2;
}());
var c2 = new C2();
var c2 = new C2(); // error C2 is private
var r2 = c2.constructor;
//// [typesWithPrivateConstructor.d.ts]
declare class C {
constructor();
}
declare var c: any;
declare var r: () => void;
declare class C2 {
constructor(x);
}
declare var c2: any;
declare var r2: (x: number) => void;

View File

@ -0,0 +1,24 @@
tests/cases/conformance/types/members/typesWithProtectedConstructor.ts(6,9): error TS2674: Constructor of type '(): C' is protected and only accessible within class 'C'.
tests/cases/conformance/types/members/typesWithProtectedConstructor.ts(14,10): error TS2674: Constructor of type '(x: number): C2' is protected and only accessible within class 'C2'.
==== tests/cases/conformance/types/members/typesWithProtectedConstructor.ts (2 errors) ====
class C {
protected constructor() { }
}
var c = new C(); // error C is protected
~~~~~~~
!!! error TS2674: Constructor of type '(): C' is protected and only accessible within class 'C'.
var r: () => void = c.constructor;
class C2 {
protected constructor(x: number);
protected constructor(x: any) { }
}
var c2 = new C2(); // error C2 is protected
~~~~~~~~
!!! error TS2674: Constructor of type '(x: number): C2' is protected and only accessible within class 'C2'.
var r2: (x: number) => void = c2.constructor;

View File

@ -0,0 +1,45 @@
//// [typesWithProtectedConstructor.ts]
class C {
protected constructor() { }
}
var c = new C(); // error C is protected
var r: () => void = c.constructor;
class C2 {
protected constructor(x: number);
protected constructor(x: any) { }
}
var c2 = new C2(); // error C2 is protected
var r2: (x: number) => void = c2.constructor;
//// [typesWithProtectedConstructor.js]
var C = (function () {
function C() {
}
return C;
}());
var c = new C(); // error C is protected
var r = c.constructor;
var C2 = (function () {
function C2(x) {
}
return C2;
}());
var c2 = new C2(); // error C2 is protected
var r2 = c2.constructor;
//// [typesWithProtectedConstructor.d.ts]
declare class C {
constructor();
}
declare var c: any;
declare var r: () => void;
declare class C2 {
constructor(x: number);
}
declare var c2: any;
declare var r2: (x: number) => void;

View File

@ -82,7 +82,6 @@ interface E extends C {
}
class CC {
// Error, constructor cannot be protected
protected constructor() {
}
}

View File

@ -1,18 +1,20 @@
// @declaration: true
class C {
public constructor(public x: number) { }
}
class D {
private constructor(public x: number) { } // error
private constructor(public x: number) { }
}
class E {
protected constructor(public x: number) { } // error
protected constructor(public x: number) { }
}
var c = new C(1);
var d = new D(1);
var e = new E(1);
var d = new D(1); // error
var e = new E(1); // error
module Generic {
class C<T> {
@ -20,14 +22,14 @@ module Generic {
}
class D<T> {
private constructor(public x: T) { } // error
private constructor(public x: T) { }
}
class E<T> {
protected constructor(public x: T) { } // error
protected constructor(public x: T) { }
}
var c = new C(1);
var d = new D(1);
var e = new E(1);
var d = new D(1); // error
var e = new E(1); // error
}

View File

@ -0,0 +1,42 @@
// @declaration: true
class BaseA {
public constructor(public x: number) { }
createInstance() { new BaseA(1); }
}
class BaseB {
protected constructor(public x: number) { }
createInstance() { new BaseB(1); }
}
class BaseC {
private constructor(public x: number) { }
createInstance() { new BaseC(1); }
}
class DerivedA extends BaseA {
constructor(public x: number) { super(x); }
createInstance() { new DerivedA(1); }
createBaseInstance() { new BaseA(1); }
}
class DerivedB extends BaseB {
constructor(public x: number) { super(x); }
createInstance() { new DerivedB(1); }
createBaseInstance() { new BaseB(1); } // error
}
class DerivedC extends BaseC { // error
constructor(public x: number) { super(x); }
createInstance() { new DerivedC(1); }
createBaseInstance() { new BaseC(1); } // error
}
var ba = new BaseA(1);
var bb = new BaseB(1); // error
var bc = new BaseC(1); // error
var da = new DerivedA(1);
var db = new DerivedB(1);
var dc = new DerivedC(1);

View File

@ -0,0 +1,35 @@
// @declaration: true
class Foo {
constructor(public x: number) { }
}
class Bar {
public constructor(public x: number) { }
}
class Baz {
protected constructor(public x: number) { }
}
class Qux {
private constructor(public x: number) { }
}
// b is public
let a = Foo;
a = Bar;
a = Baz; // error Baz is protected
a = Qux; // error Qux is private
// b is protected
let b = Baz;
b = Foo; // error Foo is public
b = Bar; // error Baz is public
b = Qux; // error Qux is private
// c is private
let c = Qux;
c = Foo; // error Foo is public
c = Bar; // error Bar is public
c = Baz; // error Baz is protected

View File

@ -0,0 +1,34 @@
// @declaration: true
class A {
public constructor(a: boolean) // error
protected constructor(a: number) // error
private constructor(a: string)
private constructor() {
}
}
class B {
protected constructor(a: number) // error
constructor(a: string)
constructor() {
}
}
class C {
protected constructor(a: number)
protected constructor(a: string)
protected constructor() {
}
}
class D {
constructor(a: number)
constructor(a: string)
public constructor() {
}
}

View File

@ -1,10 +1,10 @@
// private constructors are not allowed
// @declaration: true
class C {
private constructor() { }
}
var c = new C();
var c = new C(); // error C is private
var r: () => void = c.constructor;
class C2 {
@ -12,5 +12,5 @@ class C2 {
private constructor(x: any) { }
}
var c2 = new C2();
var c2 = new C2(); // error C2 is private
var r2: (x: number) => void = c2.constructor;

View File

@ -0,0 +1,16 @@
// @declaration: true
class C {
protected constructor() { }
}
var c = new C(); // error C is protected
var r: () => void = c.constructor;
class C2 {
protected constructor(x: number);
protected constructor(x: any) { }
}
var c2 = new C2(); // error C2 is protected
var r2: (x: number) => void = c2.constructor;

View File

@ -0,0 +1,9 @@
/// <reference path='fourslash.ts' />
////class A {
//// private constructor() {}
////}
////var x = new A(/*1*/
goTo.marker("1");
verify.not.signatureHelpPresent();

View File

@ -0,0 +1,9 @@
/// <reference path='fourslash.ts' />
////class A {
//// protected constructor() {}
////}
////var x = new A(/*1*/
goTo.marker("1");
verify.not.signatureHelpPresent();