{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/52802646","id":52802646,"diff_hunk":"@@ -10123,6 +10170,37 @@ namespace ts {\n             return resolveErrorCall(node);\r\n         }\r\n \r\n+        function isConstructorAccessible(node: NewExpression, signature: Signature) {\r\n+            if (!signature || !signature.declaration) {\r\n+                return true;\r\n+            }\r\n+\r\n+            const declaration = signature.declaration;\r\n+            const flags = declaration.flags;\r\n+\r\n+            // Public constructor is accessible.\r\n+            if (!(flags & (NodeFlags.Private | NodeFlags.Protected))) {\r\n+                return true;\r\n+            }\r\n+\r\n+            const declaringClass = <InterfaceType>getDeclaredTypeOfSymbol(declaration.parent.symbol);\r\n+            const enclosingClassDeclaration = getContainingClass(node);\r\n+            const enclosingClass = enclosingClassDeclaration ? <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined;\r\n+\r\n+            // A private or protected constructor can only be instantiated within it's own class \r\n+            if (declaringClass !== enclosingClass) {\r","path":"src/compiler/checker.ts","position":116,"original_position":116,"commit_id":"a6a5a22a32e99c2bfd2d7eb658e7e6ce8c9588b3","original_commit_id":"a6a5a22a32e99c2bfd2d7eb658e7e6ce8c9588b3","user":{"login":"mhegazy","id":8000722,"avatar_url":"https://avatars.githubusercontent.com/u/8000722?v=3","gravatar_id":"","url":"https://api.github.com/users/mhegazy","html_url":"https://github.com/mhegazy","followers_url":"https://api.github.com/users/mhegazy/followers","following_url":"https://api.github.com/users/mhegazy/following{/other_user}","gists_url":"https://api.github.com/users/mhegazy/gists{/gist_id}","starred_url":"https://api.github.com/users/mhegazy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhegazy/subscriptions","organizations_url":"https://api.github.com/users/mhegazy/orgs","repos_url":"https://api.github.com/users/mhegazy/repos","events_url":"https://api.github.com/users/mhegazy/events{/privacy}","received_events_url":"https://api.github.com/users/mhegazy/received_events","type":"User","site_admin":false},"body":"as noted in , we https://github.com/Microsoft/TypeScript/issues/7059, if here is not sufficient, it should be a while loop walking up, looking at all enclosing classes, so that something like this should be legal:\r\n\r\n```ts\r\n\r\nclass B {\r\n    private constructor() { }\r\n\r\n    method() {\r\n        class C {\r\n            method() {\r\n                new B(); // should be fine\r\n            }\r\n        }\r\n    }\r\n}\r\n```","created_at":"2016-02-12T21:46:39Z","updated_at":"2016-02-12T21:46:39Z","html_url":"https://github.com/Microsoft/TypeScript/pull/6885#discussion_r52802646","pull_request_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/6885","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/52802646"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/6885#discussion_r52802646"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/6885"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/6885","id":58215129,"html_url":"https://github.com/Microsoft/TypeScript/pull/6885","diff_url":"https://github.com/Microsoft/TypeScript/pull/6885.diff","patch_url":"https://github.com/Microsoft/TypeScript/pull/6885.patch","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/6885","number":6885,"state":"open","locked":false,"title":"Constructor Visibility","user":{"login":"AbubakerB","id":6986076,"avatar_url":"https://avatars.githubusercontent.com/u/6986076?v=3","gravatar_id":"","url":"https://api.github.com/users/AbubakerB","html_url":"https://github.com/AbubakerB","followers_url":"https://api.github.com/users/AbubakerB/followers","following_url":"https://api.github.com/users/AbubakerB/following{/other_user}","gists_url":"https://api.github.com/users/AbubakerB/gists{/gist_id}","starred_url":"https://api.github.com/users/AbubakerB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AbubakerB/subscriptions","organizations_url":"https://api.github.com/users/AbubakerB/orgs","repos_url":"https://api.github.com/users/AbubakerB/repos","events_url":"https://api.github.com/users/AbubakerB/events{/privacy}","received_events_url":"https://api.github.com/users/AbubakerB/received_events","type":"User","site_admin":false},"body":"## Constructor Visibility\r\n(_This is a updated PR from #4174_)\r\n\r\nThere wasn't any detailed proposal, so I'm just going to list what this PR implements.\r\n\r\n#### 1) Constructor Visibility\r\n\r\n1. A constructor can now have the `private` or `protected` keyword on its signature.\r\n2. All constructor overloads must be of the same visibility (i.e. all `private`, `protected`, or `public`)\r\n\r\n#### 2) Private Constructors\r\n\r\nA class with a private constructor:\r\n\r\n1. Can only be instantiated within it's own class.\r\n2. Cannot be extended. _(Currently, this implementation does not throw an error on the `super` call of the derived type since there is already an error when extending the class. I can add an error to the `super` call if you guys think it's beneficial)_\r\n\r\n#### 3) Protected Constructors\r\n\r\nA class with a protected constructor:\r\n\r\n1. Can only be instantiated within it's own class.\r\n2. Can be extended.\r\n\r\n#### 4) Signature Assignability \r\n\r\n- A public, protected and private signature is assignable to a private signature.\r\n- A public and protected signature is assignable to a protected signature.\r\n- A public signature is assignable to public signature.","created_at":"2016-02-03T22:57:35Z","updated_at":"2016-02-12T21:46:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f9cf8694fc5091f9f0164ad641d22d7263abb394","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/6885/commits","review_comments_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/6885/comments","review_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/6885/comments","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/a6a5a22a32e99c2bfd2d7eb658e7e6ce8c9588b3","head":{"label":"AbubakerB:constructorAccessibility","ref":"constructorAccessibility","sha":"a6a5a22a32e99c2bfd2d7eb658e7e6ce8c9588b3","user":{"login":"AbubakerB","id":6986076,"avatar_url":"https://avatars.githubusercontent.com/u/6986076?v=3","gravatar_id":"","url":"https://api.github.com/users/AbubakerB","html_url":"https://github.com/AbubakerB","followers_url":"https://api.github.com/users/AbubakerB/followers","following_url":"https://api.github.com/users/AbubakerB/following{/other_user}","gists_url":"https://api.github.com/users/AbubakerB/gists{/gist_id}","starred_url":"https://api.github.com/users/AbubakerB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AbubakerB/subscriptions","organizations_url":"https://api.github.com/users/AbubakerB/orgs","repos_url":"https://api.github.com/users/AbubakerB/repos","events_url":"https://api.github.com/users/AbubakerB/events{/privacy}","received_events_url":"https://api.github.com/users/AbubakerB/received_events","type":"User","site_admin":false},"repo":{"id":50963054,"name":"TypeScript","full_name":"AbubakerB/TypeScript","owner":{"login":"AbubakerB","id":6986076,"avatar_url":"https://avatars.githubusercontent.com/u/6986076?v=3","gravatar_id":"","url":"https://api.github.com/users/AbubakerB","html_url":"https://github.com/AbubakerB","followers_url":"https://api.github.com/users/AbubakerB/followers","following_url":"https://api.github.com/users/AbubakerB/following{/other_user}","gists_url":"https://api.github.com/users/AbubakerB/gists{/gist_id}","starred_url":"https://api.github.com/users/AbubakerB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AbubakerB/subscriptions","organizations_url":"https://api.github.com/users/AbubakerB/orgs","repos_url":"https://api.github.com/users/AbubakerB/repos","events_url":"https://api.github.com/users/AbubakerB/events{/privacy}","received_events_url":"https://api.github.com/users/AbubakerB/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/AbubakerB/TypeScript","description":"TypeScript is a superset of JavaScript that compiles to clean JavaScript output.","fork":true,"url":"https://api.github.com/repos/AbubakerB/TypeScript","forks_url":"https://api.github.com/repos/AbubakerB/TypeScript/forks","keys_url":"https://api.github.com/repos/AbubakerB/TypeScript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AbubakerB/TypeScript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AbubakerB/TypeScript/teams","hooks_url":"https://api.github.com/repos/AbubakerB/TypeScript/hooks","issue_events_url":"https://api.github.com/repos/AbubakerB/TypeScript/issues/events{/number}","events_url":"https://api.github.com/repos/AbubakerB/TypeScript/events","assignees_url":"https://api.github.com/repos/AbubakerB/TypeScript/assignees{/user}","branches_url":"https://api.github.com/repos/AbubakerB/TypeScript/branches{/branch}","tags_url":"https://api.github.com/repos/AbubakerB/TypeScript/tags","blobs_url":"https://api.github.com/repos/AbubakerB/TypeScript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AbubakerB/TypeScript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AbubakerB/TypeScript/git/refs{/sha}","trees_url":"https://api.github.com/repos/AbubakerB/TypeScript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AbubakerB/TypeScript/statuses/{sha}","languages_url":"https://api.github.com/repos/AbubakerB/TypeScript/languages","stargazers_url":"https://api.github.com/repos/AbubakerB/TypeScript/stargazers","contributors_url":"https://api.github.com/repos/AbubakerB/TypeScript/contributors","subscribers_url":"https://api.github.com/repos/AbubakerB/TypeScript/subscribers","subscription_url":"https://api.github.com/repos/AbubakerB/TypeScript/subscription","commits_url":"https://api.github.com/repos/AbubakerB/TypeScript/commits{/sha}","git_commits_url":"https://api.github.com/repos/AbubakerB/TypeScript/git/commits{/sha}","comments_url":"https://api.github.com/repos/AbubakerB/TypeScript/comments{/number}","issue_comment_url":"https://api.github.com/repos/AbubakerB/TypeScript/issues/comments{/number}","contents_url":"https://api.github.com/repos/AbubakerB/TypeScript/contents/{+path}","compare_url":"https://api.github.com/repos/AbubakerB/TypeScript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AbubakerB/TypeScript/merges","archive_url":"https://api.github.com/repos/AbubakerB/TypeScript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AbubakerB/TypeScript/downloads","issues_url":"https://api.github.com/repos/AbubakerB/TypeScript/issues{/number}","pulls_url":"https://api.github.com/repos/AbubakerB/TypeScript/pulls{/number}","milestones_url":"https://api.github.com/repos/AbubakerB/TypeScript/milestones{/number}","notifications_url":"https://api.github.com/repos/AbubakerB/TypeScript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AbubakerB/TypeScript/labels{/name}","releases_url":"https://api.github.com/repos/AbubakerB/TypeScript/releases{/id}","deployments_url":"https://api.github.com/repos/AbubakerB/TypeScript/deployments","created_at":"2016-02-03T00:48:50Z","updated_at":"2016-02-03T00:49:24Z","pushed_at":"2016-02-05T18:53:46Z","git_url":"git://github.com/AbubakerB/TypeScript.git","ssh_url":"git@github.com:AbubakerB/TypeScript.git","clone_url":"https://github.com/AbubakerB/TypeScript.git","svn_url":"https://github.com/AbubakerB/TypeScript","homepage":"http://www.typescriptlang.org","size":233642,"stargazers_count":0,"watchers_count":0,"language":"TypeScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"98b8af62e7f2afd42f70de286c8a45eb00651428","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":20929025,"name":"TypeScript","full_name":"Microsoft/TypeScript","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/TypeScript","description":"TypeScript is a superset of JavaScript that compiles to clean JavaScript output.","fork":false,"url":"https://api.github.com/repos/Microsoft/TypeScript","forks_url":"https://api.github.com/repos/Microsoft/TypeScript/forks","keys_url":"https://api.github.com/repos/Microsoft/TypeScript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/TypeScript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/TypeScript/teams","hooks_url":"https://api.github.com/repos/Microsoft/TypeScript/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/TypeScript/events","assignees_url":"https://api.github.com/repos/Microsoft/TypeScript/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/TypeScript/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/TypeScript/tags","blobs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/TypeScript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/TypeScript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/TypeScript/languages","stargazers_url":"https://api.github.com/repos/Microsoft/TypeScript/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/TypeScript/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/TypeScript/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/TypeScript/subscription","commits_url":"https://api.github.com/repos/Microsoft/TypeScript/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/TypeScript/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/TypeScript/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/TypeScript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/TypeScript/merges","archive_url":"https://api.github.com/repos/Microsoft/TypeScript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/TypeScript/downloads","issues_url":"https://api.github.com/repos/Microsoft/TypeScript/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/TypeScript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/TypeScript/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/TypeScript/deployments","created_at":"2014-06-17T15:28:39Z","updated_at":"2016-02-12T20:07:25Z","pushed_at":"2016-02-12T21:37:07Z","git_url":"git://github.com/Microsoft/TypeScript.git","ssh_url":"git@github.com:Microsoft/TypeScript.git","clone_url":"https://github.com/Microsoft/TypeScript.git","svn_url":"https://github.com/Microsoft/TypeScript","homepage":"http://www.typescriptlang.org","size":473240,"stargazers_count":9359,"watchers_count":9359,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1137,"mirror_url":null,"open_issues_count":1027,"forks":1137,"open_issues":1027,"watchers":9359,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/6885"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/6885"},"issue":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/6885"},"comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/6885/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/6885/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/6885/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/TypeScript/statuses/a6a5a22a32e99c2bfd2d7eb658e7e6ce8c9588b3"}}}}