bug icon indicating copy to clipboard operation
bug copied to clipboard

Inference failure with -Ypartial-unification

Open lrytz opened this issue 10 months ago • 1 comments

Not sure if it's a bug, or if there are fundamental reasons why inference cannot succeed.

object Q {
  def f[T, F[X <: T]](s: F[T])(implicit c: Co[T, F]) = ???
}

trait Itr[+A]

trait Co[U, -F[_ <: U]]
object Co {
  implicit def i[E]: Co[E, Itr] = ???
}

class K
object K extends VS[K, VH[K]]

trait VS[V, H <: VH[V]] extends Itr[V]
trait VH[+A]

class Test {
  // these all work with 2.12, but fail with 2.13
  // they also fail with Scala 3, and with 2.12 with -Ypartial-unification
  //    inferred kinds of the type arguments (VH[K],[H <: VH[V]]VS[K,H]) do not conform to the expected kinds of the type parameters (type T,type F).
  //    [H <: VH[V]]VS[K,H]'s type parameters do not match type F's expected parameters:
  //    type H's bounds <: VH[V] are stricter than type X's declared bounds <: T
  Q.f(K)
  // Q.f(K)(Co.i)
  // Q.f(K)(Co.i[K])
  // Q.f(K)(Co.i[K])

  // works on 2.12, 2.13, Scala 3
  // Q.f[K, Itr](K)
}

lrytz avatar Jan 29 '25 12:01 lrytz

https://gist.github.com/djspiewak/7a81a395c461fd3a09a6941d4cd040f2 for the study group

lrytz avatar Jan 31 '25 10:01 lrytz