{"action":"closed","issue":{"url":"https://api.github.com/repos/scala-js/scala-js/issues/3338","repository_url":"https://api.github.com/repos/scala-js/scala-js","labels_url":"https://api.github.com/repos/scala-js/scala-js/issues/3338/labels{/name}","comments_url":"https://api.github.com/repos/scala-js/scala-js/issues/3338/comments","events_url":"https://api.github.com/repos/scala-js/scala-js/issues/3338/events","html_url":"https://github.com/scala-js/scala-js/issues/3338","id":312314256,"number":3338,"title":"[0.6.x] Wrong optimization of array_apply() on an Array[Array[Char]]","user":{"login":"sjrd","id":535934,"avatar_url":"https://avatars3.githubusercontent.com/u/535934?v=4","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},"labels":[{"id":28856109,"url":"https://api.github.com/repos/scala-js/scala-js/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"closed","locked":false,"assignee":{"login":"sjrd","id":535934,"avatar_url":"https://avatars3.githubusercontent.com/u/535934?v=4","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},"assignees":[{"login":"sjrd","id":535934,"avatar_url":"https://avatars3.githubusercontent.com/u/535934?v=4","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}],"milestone":{"url":"https://api.github.com/repos/scala-js/scala-js/milestones/55","html_url":"https://github.com/scala-js/scala-js/milestone/55","labels_url":"https://api.github.com/repos/scala-js/scala-js/milestones/55/labels","id":3052749,"number":55,"title":"v0.6.23","description":"","creator":{"login":"sjrd","id":535934,"avatar_url":"https://avatars3.githubusercontent.com/u/535934?v=4","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},"open_issues":2,"closed_issues":6,"state":"open","created_at":"2018-01-22T08:13:39Z","updated_at":"2018-04-09T04:25:38Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2018-04-08T15:23:00Z","updated_at":"2018-04-09T04:25:38Z","closed_at":"2018-04-09T04:25:38Z","author_association":"OWNER","body":"The following code crashes on the first `isInstanceOf`:\r\n```scala\r\n  def main(args: Array[String]): Unit = {\r\n    import js.DynamicImplicits.truthValue\r\n\r\n    val a = Array(Array('a'))\r\n    val b = arrayGet(a, 0)\r\n    assert(b.isInstanceOf[Array[Char]])\r\n    val c = b.asInstanceOf[Array[Char]]\r\n    val d = arrayGet(c, 0)\r\n    assert(d.isInstanceOf[Char])\r\n    assert(d == 'a')\r\n  }\r\n\r\n  @inline\r\n  def arrayGet[A](a: Array[A], i: Int): Any = a(i)\r\n```\r\n`a(i)` is compiled down to `ScalaRunTime.array_apply(a, i)` because `a` is a polymorphic array. There's a wrong optimization of `array_apply(a, i)` in this case because `a` is an `Array[Array[Char]]`: the optimizer wants to box the `Array[Char]` it gets from `a[i]` into a `java.lang.Character`.\r\n\r\nThe problematic test is [here](https://github.com/scala-js/scala-js/blob/a4bce397ba035e0d6b2c8454ae29c8739ece5ad5/tools/shared/src/main/scala/org/scalajs/core/tools/linker/frontend/optimizer/OptimizerCore.scala#L1980). It is missing an `&& depth == 1`.\r\n\r\nThe bug does not exist in 1.x obviously, because of cc56fe758fbd1e6505ba05494142eb89b159780e"}}
{"actor":{"display_login":"sjrd"}}