Open majk-p opened 3 days ago
Thank you for the bug report!
Bisect on main points to 0337efdc63095209d2de6f6fe57ea346def7e2b5 Last good release: 3.4.1-RC1-bin-20240210-6efcdba-NIGHTLY First bad release: 3.4.1-RC1-bin-20240212-c529a48-NIGHTLY
I'm preparing a self-contained minimization
Self contained minimization with the same error:
//> using options -Ykind-projector:underscores
import java.util.UUID
object MyId:
def fromUUID[F[_]: Functor: UUIDGen]: F[String] =
toFunctorOps(UUIDGen[F].randomUUID).map(fromUUID) // error
private def fromUUID(id: UUID): String = ???
object UUIDGen:
def apply[F[_]](implicit ev: UUIDGen[F]): UUIDGen[F] = ev
trait UUIDGen[F[_]]:
def randomUUID: F[UUID]
trait FlatMap[F[_]] extends Functor[F]
trait Functor[F[_]] extends Invariant[F]
trait Invariant[F[_]]
object Invariant:
implicit def catsFlatMapForMap[K]: FlatMap[Map[K, _]] = ???
implicit def catsFlatMapForSortedMap[K]: FlatMap[scala.collection.SortedMap[K, _]] = ???
implicit def toFunctorOps[F[_], A](target: F[A])(implicit tc: Functor[F]): Ops[F, A] { type TypeClassType = Functor[F]} =
new Ops[F, A] { type TypeClassType = Functor[F] }
trait Ops[F[_], A] {
type TypeClassType <: Functor[F]
def map[B](f: A => B): F[B] = ???
}
The clue of the issue seems to be fact that Functor context bound parameter is being ignored, thus the issue can be further minimized to
type UUID = String
object MyId:
def fromUUID[F[_]: Functor: UUIDGen]: F[String] =
toFunctorOps(UUIDGen[F].randomUUID).map(fromUUID) // error
private def fromUUID(id: UUID): String = ???
object UUIDGen:
def apply[F[_]](implicit ev: UUIDGen[F]): UUIDGen[F] = ev
trait UUIDGen[F[_]]:
def randomUUID: F[UUID]
trait Functor[F[_]]
implicit def toFunctorOps[F[_], A](target: F[A])(implicit tc: Functor[F]): Ops[F, A] { type TypeClassType = Functor[F]} =
new Ops[F, A] { type TypeClassType = Functor[F] }
trait Ops[F[_], A] {
type TypeClassType <: Functor[F]
def map[B](f: A => B): F[B] = ???
}
Failing with
[error] ./test_selfcontained.scala:4:53
[error] No given instance of type Functor[F] was found for a context parameter of method fromUUID in object MyId
[error]
[error] where: F is a type variable with constraint <: [R] =>> String => R
[error] toFunctorOps(UUIDGen[F].randomUUID).map(fromUUID)
[error] ^
Compiler version
The attached code compiled well up to
3.3.3
and stopped compiling with3.3.4
. Compilation also fails on latest3.5.1
.Minimized code
Also available as a gist https://gist.github.com/majk-p/b510b46cb38ecbb9bc7dd29c30a1055f
Notice how this only affects the short syntax without explicit parentheses. Adding
(_)
solves the issue. Changing the second method name to anything non-ambiguous also fixes the example, this means following example also works:Output
Expectation
Compiles with no issues
Additional research
I found the great bisect tool in compiler sources and run it against my example code. Here's the output:
This is how I configured the bisect tool:
It looks like https://github.com/scala/scala3/pull/20862 is the PR that introduced the regression. CC: @WojciechMazur @bishabosha