{"action":"created","comment":{"url":"https://api.github.com/repos/scala-js/scala-js/pulls/comments/37696542","id":37696542,"diff_hunk":"@@ -233,14 +246,63 @@ class IRChecker(unit: LinkingUnit, logger: Logger) {\n       }\n     }\n \n-    if (resultType != AnyType) {\n-      reportError(s\"Result type of exported method def is $resultType, \"+\n-          \"but must be Any\")\n+    if (classDef.kind == ClassKind.JSClass && name == \"constructor\") {\n+      checkJSClassConstructor(methodDef, classDef)\n+    } else {\n+      if (resultType != AnyType) {\n+        reportError(s\"Result type of exported method def is $resultType, \"+\n+            \"but must be Any\")\n+      }\n+\n+      val thisType =\n+        if (classDef.kind == ClassKind.JSClass) AnyType\n+        else ClassType(classDef.name.name)\n+\n+      val bodyEnv = Env.fromSignature(thisType, params, resultType)\n+      typecheckExpect(body, bodyEnv, resultType)\n     }\n+  }\n \n-    val thisType = ClassType(classDef.name.name)\n-    val bodyEnv = Env.fromSignature(thisType, params, resultType)\n-    typecheckExpect(body, bodyEnv, resultType)\n+  def checkJSClassConstructor(methodDef: MethodDef,\n+      classDef: LinkedClass): Unit = {\n+    val MethodDef(static, _, params, resultType, body) = methodDef\n+    implicit val ctx = ErrorContext(methodDef)\n+\n+    if (resultType != NoType) {\n+      reportError(s\"Result type of JS class constructor is $resultType, \"+\n+          \"but must be NoType\")\n+    }\n+\n+    val bodyStats = body match {\n+      case Block(stats) => stats\n+      case _            => body :: Nil\n+    }\n+\n+    val (prepStats, superCallAndRest) =\n+      bodyStats.span(!_.isInstanceOf[JSSuperConstructorCall])\n+\n+    val (superCall, restStats) = superCallAndRest match {\n+      case (superCall: JSSuperConstructorCall) :: restStats =>\n+        (superCall, restStats)\n+      case _ =>\n+        reportError(\n+            \"A JS class constructor must contain one super constructor call \" +\n+            \"at the top-level\")\n+        (JSSuperConstructorCall(Nil)(methodDef.pos), Nil)\n+    }\n+\n+    val initialEnv = Env.fromSignature(NoType, params, NoType,\n+        isConstructor = true)\n+\n+    val preparedEnv = (initialEnv /: prepStats) { (prevEnv, stat) =>\n+      typecheckStat(stat, prevEnv)\n+    }\n+\n+    for (arg <- superCall.args)\n+      typecheckExprOrSpread(arg, preparedEnv)","path":"tools/shared/src/main/scala/org/scalajs/core/tools/optimizer/IRChecker.scala","position":99,"original_position":99,"commit_id":"616613181724f8587df016cb3e5a2d3494bbb684","original_commit_id":"616613181724f8587df016cb3e5a2d3494bbb684","user":{"login":"gzm0","id":1140323,"avatar_url":"https://avatars.githubusercontent.com/u/1140323?v=3","gravatar_id":"","url":"https://api.github.com/users/gzm0","html_url":"https://github.com/gzm0","followers_url":"https://api.github.com/users/gzm0/followers","following_url":"https://api.github.com/users/gzm0/following{/other_user}","gists_url":"https://api.github.com/users/gzm0/gists{/gist_id}","starred_url":"https://api.github.com/users/gzm0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gzm0/subscriptions","organizations_url":"https://api.github.com/users/gzm0/orgs","repos_url":"https://api.github.com/users/gzm0/repos","events_url":"https://api.github.com/users/gzm0/events{/privacy}","received_events_url":"https://api.github.com/users/gzm0/received_events","type":"User","site_admin":false},"body":"I thought we don't allow spread here yet.","created_at":"2015-08-22T15:15:07Z","updated_at":"2015-08-22T15:15:07Z","html_url":"https://github.com/scala-js/scala-js/pull/1809#discussion_r37696542","pull_request_url":"https://api.github.com/repos/scala-js/scala-js/pulls/1809","_links":{"self":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/comments/37696542"},"html":{"href":"https://github.com/scala-js/scala-js/pull/1809#discussion_r37696542"},"pull_request":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/1809"}}},"pull_request":{"url":"https://api.github.com/repos/scala-js/scala-js/pulls/1809","id":40313956,"html_url":"https://github.com/scala-js/scala-js/pull/1809","diff_url":"https://github.com/scala-js/scala-js/pull/1809.diff","patch_url":"https://github.com/scala-js/scala-js/pull/1809.patch","issue_url":"https://api.github.com/repos/scala-js/scala-js/issues/1809","number":1809,"state":"open","locked":false,"title":"Fix #1795: Essentials of Scala.js-defined JS classes.","user":{"login":"sjrd","id":535934,"avatar_url":"https://avatars.githubusercontent.com/u/535934?v=3","gravatar_id":"","url":"https://api.github.com/users/sjrd","html_url":"https://github.com/sjrd","followers_url":"https://api.github.com/users/sjrd/followers","following_url":"https://api.github.com/users/sjrd/following{/other_user}","gists_url":"https://api.github.com/users/sjrd/gists{/gist_id}","starred_url":"https://api.github.com/users/sjrd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sjrd/subscriptions","organizations_url":"https://api.github.com/users/sjrd/orgs","repos_url":"https://api.github.com/users/sjrd/repos","events_url":"https://api.github.com/users/sjrd/events{/privacy}","received_events_url":"https://api.github.com/users/sjrd/received_events","type":"User","site_admin":false},"body":"This PR implements most of the specification for Scala.js-defined JavaScript classes, as discussed in #1795.\r\n\r\nThe following features are not yet supported, and are reported as implementation restrictions:\r\n\r\n* #1811 Secondary constructors\r\n* #1812 Exporting a Scala.js-defined JS class\r\n* #1813 Calling the super constructor with `:_*` to a varargs param.\r\n\r\nThis PR does not implement the deprecations that would lead to nicer definitions either. These aspects will come as follow ups, since they are not critical to the general specification.","created_at":"2015-07-19T19:58:01Z","updated_at":"2015-08-22T15:15:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"af5d31bb371ad66c27b0ed4b1df65b4205f9af24","assignee":{"login":"gzm0","id":1140323,"avatar_url":"https://avatars.githubusercontent.com/u/1140323?v=3","gravatar_id":"","url":"https://api.github.com/users/gzm0","html_url":"https://github.com/gzm0","followers_url":"https://api.github.com/users/gzm0/followers","following_url":"https://api.github.com/users/gzm0/following{/other_user}","gists_url":"https://api.github.com/users/gzm0/gists{/gist_id}","starred_url":"https://api.github.com/users/gzm0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gzm0/subscriptions","organizations_url":"https://api.github.com/users/gzm0/orgs","repos_url":"https://api.github.com/users/gzm0/repos","events_url":"https://api.github.com/users/gzm0/events{/privacy}","received_events_url":"https://api.github.com/users/gzm0/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/scala-js/scala-js/pulls/1809/commits","review_comments_url":"https://api.github.com/repos/scala-js/scala-js/pulls/1809/comments","review_comment_url":"https://api.github.com/repos/scala-js/scala-js/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scala-js/scala-js/issues/1809/comments","statuses_url":"https://api.github.com/repos/scala-js/scala-js/statuses/616613181724f8587df016cb3e5a2d3494bbb684","head":{"label":"sjrd:sjs-defined-js-classes","ref":"sjs-defined-js-classes","sha":"616613181724f8587df016cb3e5a2d3494bbb684","user":{"login":"sjrd","id":535934,"avatar_url":"https://avatars.githubusercontent.com/u/535934?v=3","gravatar_id":"","url":"https://api.github.com/users/sjrd","html_url":"https://github.com/sjrd","followers_url":"https://api.github.com/users/sjrd/followers","following_url":"https://api.github.com/users/sjrd/following{/other_user}","gists_url":"https://api.github.com/users/sjrd/gists{/gist_id}","starred_url":"https://api.github.com/users/sjrd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sjrd/subscriptions","organizations_url":"https://api.github.com/users/sjrd/orgs","repos_url":"https://api.github.com/users/sjrd/repos","events_url":"https://api.github.com/users/sjrd/events{/privacy}","received_events_url":"https://api.github.com/users/sjrd/received_events","type":"User","site_admin":false},"repo":{"id":8660284,"name":"scala-js","full_name":"sjrd/scala-js","owner":{"login":"sjrd","id":535934,"avatar_url":"https://avatars.githubusercontent.com/u/535934?v=3","gravatar_id":"","url":"https://api.github.com/users/sjrd","html_url":"https://github.com/sjrd","followers_url":"https://api.github.com/users/sjrd/followers","following_url":"https://api.github.com/users/sjrd/following{/other_user}","gists_url":"https://api.github.com/users/sjrd/gists{/gist_id}","starred_url":"https://api.github.com/users/sjrd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sjrd/subscriptions","organizations_url":"https://api.github.com/users/sjrd/orgs","repos_url":"https://api.github.com/users/sjrd/repos","events_url":"https://api.github.com/users/sjrd/events{/privacy}","received_events_url":"https://api.github.com/users/sjrd/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sjrd/scala-js","description":"Scala.js, a Scala to JavaScript compiler","fork":true,"url":"https://api.github.com/repos/sjrd/scala-js","forks_url":"https://api.github.com/repos/sjrd/scala-js/forks","keys_url":"https://api.github.com/repos/sjrd/scala-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sjrd/scala-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sjrd/scala-js/teams","hooks_url":"https://api.github.com/repos/sjrd/scala-js/hooks","issue_events_url":"https://api.github.com/repos/sjrd/scala-js/issues/events{/number}","events_url":"https://api.github.com/repos/sjrd/scala-js/events","assignees_url":"https://api.github.com/repos/sjrd/scala-js/assignees{/user}","branches_url":"https://api.github.com/repos/sjrd/scala-js/branches{/branch}","tags_url":"https://api.github.com/repos/sjrd/scala-js/tags","blobs_url":"https://api.github.com/repos/sjrd/scala-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sjrd/scala-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sjrd/scala-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/sjrd/scala-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sjrd/scala-js/statuses/{sha}","languages_url":"https://api.github.com/repos/sjrd/scala-js/languages","stargazers_url":"https://api.github.com/repos/sjrd/scala-js/stargazers","contributors_url":"https://api.github.com/repos/sjrd/scala-js/contributors","subscribers_url":"https://api.github.com/repos/sjrd/scala-js/subscribers","subscription_url":"https://api.github.com/repos/sjrd/scala-js/subscription","commits_url":"https://api.github.com/repos/sjrd/scala-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/sjrd/scala-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/sjrd/scala-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/sjrd/scala-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/sjrd/scala-js/contents/{+path}","compare_url":"https://api.github.com/repos/sjrd/scala-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sjrd/scala-js/merges","archive_url":"https://api.github.com/repos/sjrd/scala-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sjrd/scala-js/downloads","issues_url":"https://api.github.com/repos/sjrd/scala-js/issues{/number}","pulls_url":"https://api.github.com/repos/sjrd/scala-js/pulls{/number}","milestones_url":"https://api.github.com/repos/sjrd/scala-js/milestones{/number}","notifications_url":"https://api.github.com/repos/sjrd/scala-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sjrd/scala-js/labels{/name}","releases_url":"https://api.github.com/repos/sjrd/scala-js/releases{/id}","created_at":"2013-03-08T21:32:59Z","updated_at":"2015-07-30T04:16:29Z","pushed_at":"2015-08-22T12:42:56Z","git_url":"git://github.com/sjrd/scala-js.git","ssh_url":"git@github.com:sjrd/scala-js.git","clone_url":"https://github.com/sjrd/scala-js.git","svn_url":"https://github.com/sjrd/scala-js","homepage":"http://www.scala-js.org/","size":13665,"stargazers_count":12,"watchers_count":12,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":12,"default_branch":"master"}},"base":{"label":"scala-js:master","ref":"master","sha":"75126530641b90edd873c3e094598fe1898fc351","user":{"login":"scala-js","id":6039724,"avatar_url":"https://avatars.githubusercontent.com/u/6039724?v=3","gravatar_id":"","url":"https://api.github.com/users/scala-js","html_url":"https://github.com/scala-js","followers_url":"https://api.github.com/users/scala-js/followers","following_url":"https://api.github.com/users/scala-js/following{/other_user}","gists_url":"https://api.github.com/users/scala-js/gists{/gist_id}","starred_url":"https://api.github.com/users/scala-js/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scala-js/subscriptions","organizations_url":"https://api.github.com/users/scala-js/orgs","repos_url":"https://api.github.com/users/scala-js/repos","events_url":"https://api.github.com/users/scala-js/events{/privacy}","received_events_url":"https://api.github.com/users/scala-js/received_events","type":"Organization","site_admin":false},"repo":{"id":8272315,"name":"scala-js","full_name":"scala-js/scala-js","owner":{"login":"scala-js","id":6039724,"avatar_url":"https://avatars.githubusercontent.com/u/6039724?v=3","gravatar_id":"","url":"https://api.github.com/users/scala-js","html_url":"https://github.com/scala-js","followers_url":"https://api.github.com/users/scala-js/followers","following_url":"https://api.github.com/users/scala-js/following{/other_user}","gists_url":"https://api.github.com/users/scala-js/gists{/gist_id}","starred_url":"https://api.github.com/users/scala-js/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scala-js/subscriptions","organizations_url":"https://api.github.com/users/scala-js/orgs","repos_url":"https://api.github.com/users/scala-js/repos","events_url":"https://api.github.com/users/scala-js/events{/privacy}","received_events_url":"https://api.github.com/users/scala-js/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scala-js/scala-js","description":"Scala.js, the Scala to JavaScript compiler","fork":false,"url":"https://api.github.com/repos/scala-js/scala-js","forks_url":"https://api.github.com/repos/scala-js/scala-js/forks","keys_url":"https://api.github.com/repos/scala-js/scala-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scala-js/scala-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scala-js/scala-js/teams","hooks_url":"https://api.github.com/repos/scala-js/scala-js/hooks","issue_events_url":"https://api.github.com/repos/scala-js/scala-js/issues/events{/number}","events_url":"https://api.github.com/repos/scala-js/scala-js/events","assignees_url":"https://api.github.com/repos/scala-js/scala-js/assignees{/user}","branches_url":"https://api.github.com/repos/scala-js/scala-js/branches{/branch}","tags_url":"https://api.github.com/repos/scala-js/scala-js/tags","blobs_url":"https://api.github.com/repos/scala-js/scala-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scala-js/scala-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scala-js/scala-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/scala-js/scala-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scala-js/scala-js/statuses/{sha}","languages_url":"https://api.github.com/repos/scala-js/scala-js/languages","stargazers_url":"https://api.github.com/repos/scala-js/scala-js/stargazers","contributors_url":"https://api.github.com/repos/scala-js/scala-js/contributors","subscribers_url":"https://api.github.com/repos/scala-js/scala-js/subscribers","subscription_url":"https://api.github.com/repos/scala-js/scala-js/subscription","commits_url":"https://api.github.com/repos/scala-js/scala-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/scala-js/scala-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/scala-js/scala-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/scala-js/scala-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/scala-js/scala-js/contents/{+path}","compare_url":"https://api.github.com/repos/scala-js/scala-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scala-js/scala-js/merges","archive_url":"https://api.github.com/repos/scala-js/scala-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scala-js/scala-js/downloads","issues_url":"https://api.github.com/repos/scala-js/scala-js/issues{/number}","pulls_url":"https://api.github.com/repos/scala-js/scala-js/pulls{/number}","milestones_url":"https://api.github.com/repos/scala-js/scala-js/milestones{/number}","notifications_url":"https://api.github.com/repos/scala-js/scala-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scala-js/scala-js/labels{/name}","releases_url":"https://api.github.com/repos/scala-js/scala-js/releases{/id}","created_at":"2013-02-18T16:33:55Z","updated_at":"2015-08-21T19:28:56Z","pushed_at":"2015-08-21T19:32:27Z","git_url":"git://github.com/scala-js/scala-js.git","ssh_url":"git@github.com:scala-js/scala-js.git","clone_url":"https://github.com/scala-js/scala-js.git","svn_url":"https://github.com/scala-js/scala-js","homepage":"http://www.scala-js.org/","size":16921,"stargazers_count":1798,"watchers_count":1798,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":160,"mirror_url":null,"open_issues_count":64,"forks":160,"open_issues":64,"watchers":1798,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/1809"},"html":{"href":"https://github.com/scala-js/scala-js/pull/1809"},"issue":{"href":"https://api.github.com/repos/scala-js/scala-js/issues/1809"},"comments":{"href":"https://api.github.com/repos/scala-js/scala-js/issues/1809/comments"},"review_comments":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/1809/comments"},"review_comment":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/1809/commits"},"statuses":{"href":"https://api.github.com/repos/scala-js/scala-js/statuses/616613181724f8587df016cb3e5a2d3494bbb684"}}}}