{"action":"created","issue":{"url":"https://api.github.com/repos/lampepfl/dotty/issues/431","labels_url":"https://api.github.com/repos/lampepfl/dotty/issues/431/labels{/name}","comments_url":"https://api.github.com/repos/lampepfl/dotty/issues/431/comments","events_url":"https://api.github.com/repos/lampepfl/dotty/issues/431/events","html_url":"https://github.com/lampepfl/dotty/issues/431","id":64336865,"number":431,"title":"Pattern Matching generates incorrect code when matching a nested case class","user":{"login":"smarter","id":63430,"avatar_url":"https://avatars.githubusercontent.com/u/63430?v=3","gravatar_id":"","url":"https://api.github.com/users/smarter","html_url":"https://github.com/smarter","followers_url":"https://api.github.com/users/smarter/followers","following_url":"https://api.github.com/users/smarter/following{/other_user}","gists_url":"https://api.github.com/users/smarter/gists{/gist_id}","starred_url":"https://api.github.com/users/smarter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smarter/subscriptions","organizations_url":"https://api.github.com/users/smarter/orgs","repos_url":"https://api.github.com/users/smarter/repos","events_url":"https://api.github.com/users/smarter/events{/privacy}","received_events_url":"https://api.github.com/users/smarter/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-03-25T18:10:43Z","updated_at":"2015-03-25T18:43:41Z","closed_at":null,"body":"The following code:\r\n```scala\r\ncase class Foo(val underlying: Int)\r\n\r\nobject O {\r\n  def test(): Unit = {\r\n    val x: Option[Foo] = Some(Foo(1))\r\n    x match {\r\n      case Some(m) =>\r\n        println(m)\r\n    }\r\n  }\r\n}\r\n```\r\nGenerates after patternMatcher:\r\n```scala\r\nfinal module class O$() extends Object() { this: O.type => \r\n  def test(): Unit = {\r\n    val x: Option[Foo] = Some.apply[Foo'](Foo.apply(1))\r\n    {\r\n      case val selector12: Option[Foo] = x\r\n      {\r\n        def case31(): Unit = {\r\n          def matchFail21(): Unit = throw new MatchError(selector12)\r\n          if selector12.isInstanceOf[Some[Foo']] then {\r\n            val x21: Some[Foo'] = selector12.asInstanceOf[Some[Foo']]\r\n            {\r\n              val o41: Option[Foo] = \r\n                Some.unapply[Foo'](selector12.asInstanceOf[Some[Foo']])\r\n              if o41.isDefined then {\r\n                val x31: Foo = o41.get\r\n                {\r\n                  val m: Foo = x31._1.asInstanceOf[Foo]\r\n                  {\r\n                    {\r\n                      println(m)\r\n                    }\r\n                  }\r\n                }\r\n              } else matchFail21()\r\n            }\r\n          } else matchFail21()\r\n        }\r\n        case31()\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\nNote that `x31` has type Foo, but the next line calls ` x31._1.asInstanceOf[Foo]` which does not make sense as the accessor of Foo has type Int, not Foo."},"comment":{"url":"https://api.github.com/repos/lampepfl/dotty/issues/comments/86167139","html_url":"https://github.com/lampepfl/dotty/issues/431#issuecomment-86167139","issue_url":"https://api.github.com/repos/lampepfl/dotty/issues/431","id":86167139,"user":{"login":"smarter","id":63430,"avatar_url":"https://avatars.githubusercontent.com/u/63430?v=3","gravatar_id":"","url":"https://api.github.com/users/smarter","html_url":"https://github.com/smarter","followers_url":"https://api.github.com/users/smarter/followers","following_url":"https://api.github.com/users/smarter/following{/other_user}","gists_url":"https://api.github.com/users/smarter/gists{/gist_id}","starred_url":"https://api.github.com/users/smarter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smarter/subscriptions","organizations_url":"https://api.github.com/users/smarter/orgs","repos_url":"https://api.github.com/users/smarter/repos","events_url":"https://api.github.com/users/smarter/events{/privacy}","received_events_url":"https://api.github.com/users/smarter/received_events","type":"User","site_admin":false},"created_at":"2015-03-25T18:43:41Z","updated_at":"2015-03-25T18:43:41Z","body":"The problem doesn't seem to happen if I replace Option by a custom case class:\r\n```scala\r\ncase class Foo(val ff: Int)\r\nsealed trait Option2[T]\r\ncase class Some2[T](underlying: T) extends Option2[T]\r\ncase object None2 extends Option2[Nothing]\r\n\r\nobject O {\r\n  def test(): Unit = {\r\n    val x: Option2[Foo] = Some2(Foo(1))\r\n    x match {\r\n      case Some2(m) =>\r\n        println(m)\r\n    }\r\n  }\r\n}\r\n```\r\nBecomes:\r\n```scala\r\nfinal module class O$() extends Object() { this: O.type => \r\n  def test(): Unit = {\r\n    val x: Option2[Foo] = Some2.apply[Foo'](Foo.apply(1))\r\n    {\r\n      case val selector13: Option2[Foo] = x\r\n      {\r\n        def case51(): Unit = {\r\n          def matchFail31(): Unit = throw new MatchError(selector13)\r\n          if selector13.isInstanceOf[Some2[Foo']] then {\r\n            val x21: Some2[Foo'] = selector13.asInstanceOf[Some2[Foo']]\r\n            {\r\n              val x31: Some2[Foo] = \r\n                Some2.unapply[Foo'](selector13.asInstanceOf[Some2[Foo']])\r\n              {\r\n                val m: Foo = x31._1\r\n                {\r\n                  {\r\n                    println(m)\r\n                  }\r\n                }\r\n              }\r\n            }\r\n          } else matchFail31()\r\n        }\r\n        case51()\r\n      }\r\n    }\r\n  }\r\n}\r\n```"}}