I created a small example program to try to work out why a larger program wasn't compiling.
val o1: Ordered[Int] = 1
val o2: Ordered[Int] = 2
println(o1 < o2)
When I feed this to scala I get:
Ordered.scala:3: error: diverging implicit expansion for type scala.math.Ordering[Ordered[Int]]
starting with method ordered in trait LowPriorityOrderingImplicits
println(o1 < o2)
^
one error found
Using "-explaintypes" offers nothing further. However, "-Xlog-implicits" gives the following:
math.this.Ordering.comparatorToOrdering is not a valid implicit value for scala.math.Ordering[Ordered[Int]] because:
could not find implicit value for parameter cmp: java.util.Comparator[Ordered[Int]]
scala.this.Predef.conforms is not a valid implicit value for Ordered[Int] => java.lang.Comparable[Ordered[Int]] because:
type mismatch;
found : <:<[Ordered[Int],Ordered[Int]]
required: Ordered[Int] => java.lang.Comparable[Ordered[Int]]
/Users/steshaw/Projects/playground/scala/programming-in-scala/Ordered.scala:3: error: diverging implicit expansion for type scala.math.Ordering[Ordered[Int]]
starting with method ordered in trait LowPriorityOrderingImplicits
println(o1 < o2)
^
math.this.Ordering.comparatorToOrdering is not a valid implicit value for scala.math.Ordering[Ordered[Int]] because:
could not find implicit value for parameter cmp: java.util.Comparator[Ordered[Int]]
scala.this.Predef.conforms is not a valid implicit value for Ordered[Int] => java.lang.Comparable[Ordered[Int]] because:
type mismatch;
found : <:<[Ordered[Int],Ordered[Int]]
required: Ordered[Int] => java.lang.Comparable[Ordered[Int]]
one error found
but that's not helping me. Wondering what this message means and how to resolve it?
[Update] The same code today with Scala 2.11.0 produces a second error message in addition to the first about the "diverging implicit expansion". This second message is quite helpful.
$ scala Ordered.scala
Ordered.scala:3: error: diverging implicit expansion for type scala.math.Ordering[Ordered[Int]]
starting with method comparatorToOrdering in trait LowPriorityOrderingImplicits
println(o1 < o2)
^
/Users/steshaw/Projects/playground/scala/scalac-errors/Ordered.scala:3: error: type mismatch;
found : Ordered[Int]
required: Int
println(o1 < o2)
^
two errors found