-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6885 from AbubakerB/constructorAccessibility
Constructor Visibility
- Loading branch information
Showing
38 changed files
with
1,184 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
=== tests/cases/conformance/parser/ecmascript5/Protected/Protected3.ts === | ||
class C { | ||
>C : Symbol(C, Decl(Protected3.ts, 0, 0)) | ||
|
||
protected constructor() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
=== tests/cases/conformance/parser/ecmascript5/Protected/Protected3.ts === | ||
class C { | ||
>C : C | ||
|
||
protected constructor() { } | ||
} |
41 changes: 21 additions & 20 deletions
41
tests/baselines/reference/classConstructorAccessibility.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,50 @@ | ||
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 class 'D' is private and only accessible within the class declaration. | ||
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(16,9): error TS2674: Constructor of class 'E' is protected and only accessible within the class declaration. | ||
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(32,13): error TS2673: Constructor of class 'D<T>' is private and only accessible within the class declaration. | ||
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(33,13): error TS2674: Constructor of class 'E<T>' is protected and only accessible within the class declaration. | ||
|
||
|
||
==== 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 class 'D' is private and only accessible within the class declaration. | ||
var e = new E(1); // error | ||
~~~~~~~~ | ||
!!! error TS2674: Constructor of class 'E' is protected and only accessible within the class declaration. | ||
|
||
module Generic { | ||
class C<T> { | ||
public constructor(public x: T) { } | ||
} | ||
|
||
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 class 'D<T>' is private and only accessible within the class declaration. | ||
var e = new E(1); // error | ||
~~~~~~~~ | ||
!!! error TS2674: Constructor of class 'E<T>' is protected and only accessible within the class declaration. | ||
} | ||
|
Oops, something went wrong.