I have asked this question in stackoverflow: https://stackoverflow.com/questions/76440083/why-the-type-inference-failed-of-inline-method, and run it here.
I have no idea why the f2
does not compile.
trait Base
trait Schema[T <: Base]:
given Schema[T] = this
class Sub1 extends Base
object Sub1 extends Schema[Sub1]
class Sub2 extends Base
object Sub2 extends Schema[Sub2]
trait Container[T <: Base]
object Container:
import scala.compiletime.erasedValue
object C1 extends Container[Sub1]
object C2 extends Container[Sub2]
def f1[T <: Base : Schema]: Container[T] = summon[Schema[T]] match
case Sub1 => C1
case Sub2 => C2
inline def f2[T <: Base]: Container[T] = inline erasedValue[T] match
case _: Sub1 => C1
case _: Sub2 => C2