typelevel / typelevel/cats

Scala 3: No given instance of type cats.Applicative[[_] =>> Any] was found for parameter F of method apply in class PurePartiallyApplied

Open
#4,499 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
5.5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
5

Description

I am currently migrating code from scala 2.13 to Scala 3 and found a weird issue. I am not sure whether this is a bug or not. And also sure whether it should be reported here or on http4s. Opening to be sure:

The following code compiles under scala 2.13:

import org.http4s.server.AuthMiddleware
import cats.data.Kleisli
import cats.data.OptionT
val middleware = AuthMiddleware(Kleisli { _ => OptionT.pure { "foo" } })

But reports compile errors under scala3:

[error] -- [E172] Type Error: /tmp/quickstart/src/main/scala/com/example/quickstart/Main.scala:12:71 
[error] 12 |  val middleware = AuthMiddleware(Kleisli { _ => OptionT.pure { "foo" } })
[error]    |                                                                       ^
[error]    |No given instance of type cats.Applicative[[_] =>> Any] was found for parameter F of method apply in class PurePartiallyApplied
[error]    |
[error]    |One of the following imports might make progress towards fixing the problem:
[error]    |
[error]    |  import fs2.Compiler.Target.forConcurrent
[error]    |  import fs2.Compiler.Target.forSync
[error]    |
[error] -- [E172] Type Error: /tmp/quickstart/src/main/scala/com/example/quickstart/Main.scala:12:74 
[error] 12 |  val middleware = AuthMiddleware(Kleisli { _ => OptionT.pure { "foo" } })
[error]    |                                                                          ^
[error]    |No given instance of type cats.Monad[[_] =>> Any] was found for an implicit parameter of method apply in object AuthMiddleware
[error]    |
[error]    |One of the following imports might make progress towards fixing the problem:
[error]    |
[error]    |  import fs2.Compiler.Target.forConcurrent
[error]    |  import fs2.Compiler.Target.forSync
[error]    |

The following variant compiles under scala 3:

val response: Kleisli[OptionT[IO, *], Request[IO], String] = Kleisli { _ => OptionT.pure { "foo" } }
val middleware = AuthMiddleware(response)

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.

Research direction

Start by reproducing the Scala 3 snippet using AuthMiddleware, Kleisli, and OptionT, then compare it with the explicitly typed Kleisli[OptionT[IO, *], Request[IO], String] variant. Trace the inferred types and available cats.Applicative and cats.Monad instances; done means determining whether the failure is in cats or Scala 3 and documenting or covering the confirmed behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
compilers, developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.