Looks like a bug in Option orderning

I see, in 2.13.7, this code:

  trait OptionOrdering[T] extends Ordering[Option[T]] {
    def optionOrdering: Ordering[T]
    def compare(x: Option[T], y: Option[T]) = (x, y) match {
      case (None, None)       => 0
      case (None, _)          => -1
      case (_, None)          => 1
      case (Some(x), Some(y)) => optionOrdering.compare(x, y)
    }

In my case, this goes all the way down to stackoverflow error: the same method is called in the last line. (I"m also puzzled by the idea that None is above Some, but that’s judgmental.)

What do you think?
Just asking, before filing a bug.

It does not, it simply calls the compare of the values inside the two Somes
So, if you have a stack overflow I would guess that you have a custom datatype with a custom Ordering which is the one that has an error.


If you can create an Scastie that reproduces the problem we may try to see what is wrong and provide a fix.