typelevel / typelevel/cats-effect

UUIDGen Implicit Prioritization Issue on Scala 2.12

Open
#4,397 1 comment 0 reactions 1 assignee View on GitHub

@bpholt is already working on this.

Since May 1, 2025.

Dominant language
Scala
Stars
2.2k
Forks
576
Avg merge
2d 11h
Merged PRs (30d)
18

Description

Given this code (written this way to make it work with scala-cli repl, which doesn't support kind-projector):

//> using scala 2.12.20
//> using dep org.typelevel::cats-effect:3.6.1
import cats.effect._, cats.effect.std._, cats.data._
import java.util.UUID
import scala.language.higherKinds

type KIOS[a] = Kleisli[IO, String, a]

def foo[F[_]: UUIDGen]: F[UUID] = UUIDGen[F].randomUUID

SecureRandom.javaSecuritySecureRandom[IO].flatMap { implicit random =>
  foo[KIOS].run("hello world")
}

the compiler prints

error: ambiguous implicit values:
 both method catsKleisliUUIDGen in object UUIDGen of type [F[_], R](implicit evidence$4: cats.effect.std.UUIDGen[F])cats.effect.std.UUIDGen[[γ$1$]cats.data.Kleisli[F,R,γ$1$]]
 and method fromSecureRandom in object UUIDGen of type [F[_]](implicit evidence$17: cats.Functor[F], implicit evidence$18: cats.effect.std.SecureRandom[F])cats.effect.std.UUIDGen[F]
 match expected type cats.effect.std.UUIDGen[KIOS]
         foo[KIOS].run("hello world")
            ^

The repro code above compiled with CE 3.5.7.

I think the same applies to all the transformers that have instances defined on SecureRandom, so EitherT, Kleisli, OptionT, IndexedStateT, WriterT, IorT, and IndexedReaderWriterStateT.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.