Skip to content

Add unapply methods that return an Option for compatibility? #2335

Closed
@smarter

Description

@smarter

Here's an interesting problem minmized from https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/repl/ammonite/Protocol.scala that causes dotty-compiler-bootstrapped/repl to go into an infinite loop:

class Foo
case class Bar(x: Int) extends Foo

object Bar {
  def unapply(foo: Foo): Option[Int] = foo match {
    case foo: Bar =>
      unapply(foo)
  }
}

With scalac, the unapply call goes to the generated def unapply(x$1: Bar): Option[Int] , but with dotty no such method exist, instead we only generate a def unapply(x$1: Bar): Bar, so the previously perfectly correct code becomes an infinite loop!

I think we can fix this by always generating an unapply method that returns an Option, even if we don't use it.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions