scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.85k stars 1.06k forks source link

Typeclass derivation for ordering not working #6658

Closed DReigada closed 5 years ago

DReigada commented 5 years ago

The typeclass derivation example for ordering (shown here: http://dotty.epfl.ch/docs/reference/contextual/derivation.html) is not compiling.

It seems that the Ordering companion object does not define the derived method.

scala> enum Tree[T] derives Eql, Ordering, Pickling {
     |   case Branch(left: Tree[T], right: Tree[T])
     |   case Leaf(elem: T)
     | }
1 |enum Tree[T] derives Eql, Ordering, Pickling {
  |                                    ^^^^^^^^
  |                                    Not found: type Pickling
1 |enum Tree[T] derives Eql, Ordering, Pickling {
  |                          ^
  |               value derived is not a member of object scala.math.Ordering
OlivierBlanvillain commented 5 years ago

In the documentation Ordering is just an example (Commonly used examples are...) and does not refer to scala.math.Ordering. With a user defined Ordering typeclass and the appropriate typeclass derivation infrastructure in its companion object this should work as intended!

okouyad commented 2 months ago

But that is a very misleading doc. it should be explained in advanced

som-snytt commented 2 months ago

I agree that the doc is subpar. I had to learn the impl recently for checkUnused. It's just a convention but the doc sounds like magic.