Skip to content

Typer regression dotty-cps-async/dotty-cps-async #26624

Description

@WojciechMazur

Based on the OpenCB failure dotty-cps-async/dotty-cps-async - build logs and torrentdam/bittorrent - build logs

Compiler version

3.9.0-RC4

Bisect points to 32a04c8 / #25960

Compiles fine in 3.8.4

Minimized code

Original snippet (cats-effect-cps):

//> using dep org.typelevel::cats-effect-cps:0.5.0
//> using dep org.typelevel::cats-effect:3.7.0

 import cats.effect.IO
 import cats.effect.cps.*

 def program: IO[Int] = async[IO] {
   val x = IO.pure(1).await
   x + 1
 }

Self contained minimization

trait Ctx[F[_]]
trait TryCtx[F[_]] extends Ctx[F]

trait Monad[F[_]]:
  type Context <: Ctx[F]
  def pure[T](t: T): F[T]
  def apply[T](op: Context => F[T]): F[T]

object Monad:
  type Aux[F[_], C <: Ctx[F]] = Monad[F] { type Context = C }

trait TryMonad[F[_]] extends Monad[F]:
  type Context <: TryCtx[F]

class TryBody[F[_]] extends TryCtx[F]

trait TryInstance[F[_]] extends TryMonad[F]:
  type Context = TryBody[F]
  def apply[T](op: Context => F[T]): F[T] = op(TryBody())

class InferAsyncArg[F[_], C <: Ctx[F]](using val am: Monad.Aux[F, C]):
  transparent inline def apply[T](inline expr: C ?=> T): F[T] =
    am.apply(ctx => am.pure(expr(using ctx)))

transparent inline def async[F[_]](using am: Monad[F]) =
  new InferAsyncArg(using am)

case class IO[A](value: A)

implicit def ioTryMonad: TryMonad[IO] = new TryMonad[IO] with TryInstance[IO]:
  def pure[T](t: T) = IO(t)

def program: IO[Int] = async[IO] {
  1 + 1
}

Output

[error] ./test.scala:50:24
[error] Found:    (ctx : InferAsyncArg_this.am.Context)
[error] Required: InferAsyncArg[IO, ? <: TryCtx[IO]]#C
Error compiling project (Scala 3.9.0-RC4, JVM (25))

Expectation

Most likely should continue to compile

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions