Closed
Description
During the minimization of the crash found in OpenCB for https://github.com/takapi327/ldbc I've observed that context bounds and anonymous using arguments are treated differently by the compiler in cases where they're mixed with named using arguments.
When using context bounds we now get an ambiguous implicit resolution, but it's not the case in when the anonymous using arguments. This behaviour seems strange since both ways of declaring implicit ends up as being synthetic implicit parameters introduced by the compiler.
Compiler version
3.6.0-RC1-bin-20240716-bbb45ca-NIGHTLY
Minimized code
trait Functor[F[_]]:
def map[A, B](fa: F[A])(f: A => B): F[B] = ???
trait Monad[F[_]] extends Functor[F]
trait MonadError[F[_], E] extends Monad[F]:
def raiseError[A](e: E): F[A]
trait Temporal[F[_]] extends MonadError[F, Throwable]
trait FunctorOps[F[_], A]:
def map[B](f: A => B): F[B] = ???
implicit def toFunctorOps[F[_], A](target: F[A])(implicit tc: Functor[F]): FunctorOps[F, A] = ???
class ContextBounds[F[_]: Temporal](using err: MonadError[F, Throwable]):
def useCase = err.raiseError(new RuntimeException())
val bool: F[Boolean] = ???
def fails = toFunctorOps(bool).map(_ => ()) // warns under -source:3.5, // error under -source:3.6
class UsingArguments[F[_]](using Temporal[F])(using err: MonadError[F, Throwable]):
def useCase = err.raiseError(new RuntimeException())
val bool: F[Boolean] = ???
def works = toFunctorOps(bool).map(_ => ()) // warns under -source:3.5
Output
-source:3.5
[warn] ./src/main/scala/test.scala:15:33
[warn] Given search preference for Functor[F] between alternatives (ContextBounds.this.evidence$1 : Temporal[F]) and (ContextBounds.this.err : MonadError[F, Throwable]) will change
[warn] Current choice : the first alternative
[warn] New choice from Scala 3.6: none - it's ambiguous
[warn] def fails = toFunctorOps(bool).map(_ => ()) // warns under -source:3.5, // error under -source:3.6
[warn] ^
[warn] ./src/main/scala/test.scala:20:33
[warn] Given search preference for Functor[F] between alternatives (UsingArguments.this.x$1 : Temporal[F]) and (UsingArguments.this.err : MonadError[F, Throwable]) will change
[warn] Current choice : the first alternative
[warn] New choice from Scala 3.6: the second alternative
[warn] def works = toFunctorOps(bool).map(_ => ()) // warns under -source:3.5
[warn] ^
-source:3.6
[error] ./src/main/scala/test.scala:15:33
[error] Ambiguous given instances: both value evidence$1 in class ContextBounds and given instance err in class ContextBounds match type Functor[F] of parameter tc of method toFunctorOps
[error] def fails = toFunctorOps(bool).map(_ => ()) // warns under -source:3.5, // error under -source:3.6
[error]
Expectation
There might be a hole in implicit resolution logic that should be fixed.