What change in type inference brought better type inference for Option#fold in Dotty? For example
Starting dotty REPL...
scala> Option(5).fold(Left("err"))(Right(_))
val res0: Either[String, Int] = Right(5)
whilst in Scala 2.13.3 it errors
scala> Option(5).fold(Left("err"))(Right(_))
^
error: type mismatch;
found : scala.util.Right[Nothing,Int]
required: scala.util.Left[String,Nothing]
This seems to be related to multiple parameter lists such as Option#fold
fold[B](ifEmpty: => B)(f: A => B): B
which in Scala 2 work as follows
this behaviour or inference runs pretty deeply through the way that applications are type checked, and it is relied upon in APIs like foldLeft, which allow the constraints accumulated by considering the first argument list to allow you to omit types in the second argument list.
however it backfires in the above example because the "accumulated constraint" applied to second parameter list is Left[String,Nothing].