Skip to content

Regression in inference of implicit arguments #15664

Closed
@WojciechMazur

Description

@WojciechMazur

Community build regression for https://github.com/rssh/cps-async-connect (maintainer @rssh)
Based on Open Community Build #2434
Part of #15647 regressions tracker

This issue seems not to be related to avoidance changes introduced in 3.1.3 and reverts of that change as it compiles in both 3.1.1 and 3.1.3. It seems that the problem might be caused by the local Context type

Compiler version

Works with 3.1.1
Works with 3.1.3
Fails in 3.2.0-RC1
Fails in 3.2.1-RC1-bin-20220711-6efd92d-NIGHTLY

Minimized code

trait CpsMonad[F[_]]:
  type Context <: CpsMonadContext[F]
type Aux[F[_], C <: CpsMonadContext[F]] = CpsMonad[F] { type Context = C }
trait CpsMonadContext[F[_]]
trait CpsMonadInstanceContext[F[_]] extends CpsMonad[F]:
  type Context = CpsMonadInstanceContextBody[F]
class CpsMonadInstanceContextBody[F[_]](m: CpsMonadInstanceContext[F]) extends CpsMonadContext[F]
class InferAsyncArg[F[_], C <: CpsMonadContext[F]](using val am: Aux[F, C])

sealed abstract class ZManaged[-R, +E, +A]
type RManaged[-R, +A] = ZManaged[R, Throwable, A]

type ForZManaged[R, E] = [X] =>> ZManaged[R, E, X]
given zManagedCpsMonad[R, E]: CpsMonadInstanceContext[ForZManaged[R, E]] = ???

// Usage
def failing[R, E](using
    CpsMonad[ForZManaged[R, E]]
): InferAsyncArg[ForZManaged[R, E], CpsMonadInstanceContextBody[ForZManaged[R, E]]] =
  new InferAsyncArg

def compiling[R, E](using
    CpsMonad[ForZManaged[R, E]]
) =
  new InferAsyncArg[ForZManaged[R, E], CpsMonadInstanceContextBody[ForZManaged[R, E]]]

Output

[error] ./test.scala:23:3: Found:    InferAsyncArg[[X] =>> ZManaged[R, E, X], x$1.Context]
[error] Required: InferAsyncArg[ForZManaged[R, E], CpsMonadInstanceContextBody[ForZManaged[R, E]]]
[error]   new InferAsyncArg
[error]   ^^^^^^^^^^^^^^^^^

Expectation

It should compile

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions