typelevel / kittens

Automatic type class derivation for Cats
Apache License 2.0
536 stars 64 forks source link

instance not found in 3.4.0 without -source:3.3 #655

Closed joan38 closed 7 months ago

joan38 commented 7 months ago
//> using scala 3.4.0
//> using dep org.typelevel::kittens:3.2.0

import cats.kernel.Monoid
import cats.derived.auto.monoid.given

case class B(a: Option[Int])
case class A(b: Option[B])

val _ = Monoid[A].empty

In Scala 3.4.0 yelds:

[error] No given instance of type cats.derived.DerivedMonoid[scala$minus3$u002E4$minusbug$_.this.A] was found.

Workaround: Add this everywhere it fails to compile:

import scala.language.`3.3`

See: https://github.com/lampepfl/dotty/issues/19835

joroKr21 commented 7 months ago

I wonder if this was foreshadowed by https://github.com/typelevel/kittens/pull/582 But there was no explanation really.

joan38 commented 7 months ago

With kittens 3.3.0 I get some:

[error] 4 |import cats.derived.auto.semigroup.given
[error]   |                                   ^^^^^
[error]   |                                   unused import

Even on Scala 3.3.3

And if I don't given them, it fails to find the semigroups

joan38 commented 7 months ago

But the following works fine lol:

import cats.derived.auto.semigroup.given_Semigroup_A

But not:

import cats.derived.auto.semigroup.given Semigroup[?]
joroKr21 commented 7 months ago

Can you post a full example? That sounds like a bug in the linter because you are using the import.

joan38 commented 7 months ago

Ah I was trying to reproduce unsuccessfully but I forgot the scalacOptions. Here is the reproduction: https://scastie.scala-lang.org/Po0uhQLgSjyzEdnffZLi1g

joroKr21 commented 7 months ago

I think it's kinda right because you also import monoid.given which takes priority

joan38 commented 7 months ago

But having just import cats.derived.auto.monoid.given does not work either.

So is there a way to make this work without importing by name the given? Something like:

import cats.derived.auto.monoid.given
import cats.derived.auto.semigroup.given

Or:

import cats.derived.auto.monoid.given Monoid[?]
import cats.derived.auto.semigroup.given Semigroup[?]

?

joroKr21 commented 7 months ago

What do you mean by "does not work" though? If I import cats.derived.auto.monoid.given then Monoid[Rebuffers] works. If I import cats.derived.auto.semigroup.given then Semigroup[Rebuffers] works.

The only issue I can see is that if I import import cats.derived.auto.monoid.given then Semigroup[Rebuffers] doesn't work. I don't know why, but that's the same behaviour as Kittens 3.2:

No given instance of type cats.kernel.Semigroup[Playground.Rebuffers] was found for parameter ev of method apply in object Semigroup.
I found:

    cats.derived.auto.monoid.given_Monoid_A[Playground.Rebuffers](
      /* missing */
        summon[scala.util.NotGiven[cats.kernel.Monoid[Playground.Rebuffers]]]
    )

But no implicit values were found that match type scala.util.NotGiven[cats.kernel.Monoid[Playground.Rebuffers]].
joroKr21 commented 7 months ago

Hmm, I guess that means the linter is wrong after all because the import is used. Ok, best to report this in Dotty, I don't think we can do anything here.