bug icon indicating copy to clipboard operation
bug copied to clipboard

diverging implicit with context bounds

Open scabug opened this issue 12 years ago • 2 comments

The order of implicit parameters matters during use site-inference.

The method definitions below successfully compile. Actually using y and z yields a compile-time error with message: "diverging implicit expansion for type Ordering[A] starting with method Tuple9 in object Ordering"

def x[A, B](b: B)(implicit t: B => Traversable[A], o: Ordering[A]) = b
def y[A, B](b: B)(implicit o: Ordering[A], t: B => Traversable[A]) = b
def z[A: Ordering, B](b: B)(implicit t: B => Traversable[A]) = b

val ls = List(42)
x(ls) // works
y(ls) // compile time-error
z(ls) // compile time-error

scabug avatar Mar 02 '13 21:03 scabug

Imported From: https://issues.scala-lang.org/browse/SI-7205?orig=1 Reporter: Martin Egri (teknocide) Affected Versions: 2.10.1-RC1, 2.10.1

scabug avatar Mar 02 '13 21:03 scabug

Remains reproducible in Scala 2.13.16.

Scala 3.6.3 gives similar errors, e.g. Ambiguous given instances: both object Byte in object Ordering and object String in object Ordering match type Ordering[Any] of parameter o of method y

(I haven't considered if this is a bug, or if it's working-as-designed.)

SethTisue avatar Feb 04 '25 21:02 SethTisue