Skip to content

Type inference regression with implicit extension methods. #9480

Closed
@LukaJCB

Description

@LukaJCB

Minimized code

trait Monad[F[_]]

case class StateT[F[_], S, A](run: S => F[(S, A)])

implicit class MonadOps[F[_], A](private val fa: F[A]) extends AnyVal {
  def whileM_(p: F[Boolean])(implicit M: Monad[F]): F[Unit] = ???
}

def inspect[F[_], S, A](f: S => A)(implicit F: Monad[F]): StateT[F, S, A] = ???

type Id[A] = A

implicit def stateTMonad[F[_]: Monad, S]: Monad[[X] =>> StateT[F, S, X]] = ???
implicit def idMonad: Monad[Id] = ???

def increment: StateT[Id, Int, Unit] = ???

increment.whileM_(inspect(i => i > 4)).run(3)

Output

value > is not a member of Any, but could be made available as an extension method.

One of the following imports might make progress towards fixing the problem:

  import math.Ordered.orderingToOrdered
  import math.Ordering.Implicits.infixOrderingOps

no implicit argument of type Monad[([X0] =>> StateT[Id, Int, X0] | StateT[[A] =>> A, Any, X0])] was found for parameter M of method whileM_ in class MonadOps.
I found:

    main$package.stateTMonad[F, S]

But method stateTMonad does not match type Monad[([X0] =>> StateT[Id, Int, X0] | StateT[[A] =>> A, Any, X0])].

Expectation

This should compile fine as it does in Scala 2.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions