Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing @implicitNotFound for ApplicativeError and MonadError #4059

Closed
satorg opened this issue Nov 30, 2021 · 11 comments · Fixed by #4060
Closed

Missing @implicitNotFound for ApplicativeError and MonadError #4059

satorg opened this issue Nov 30, 2021 · 11 comments · Fixed by #4060
Labels
good first issue Issues that are easier to take on for first time contributors

Comments

@satorg
Copy link
Contributor

satorg commented Nov 30, 2021

Check it out:

scala> import cats.syntax.all._

scala> none[Int].raiseTo[Option]
-- Error:
1 |none[Int].raiseTo[Option]
  |                         ^
  |                      Could not find an instance of Applicative for Option

But in fact, Applicative[Option] DOES exist in the scope.

The error message for the above should look like: "Could not find an instance of ApplicativeError[Option, Int]" instead.
The reason why it is incorrect is that ApplicativeError does not have @implicitNotFound annotation applied and compiler picks one up from its parent.

@satorg satorg added the good first issue Issues that are easier to take on for first time contributors label Nov 30, 2021
@armanbilge
Copy link
Member

These errors frequently trip me up, and not just in Cats proper. E.g. if something in the CE hierarchy is missing then it says you are missing Monad (and not Concurrent or Async).

@djspiewak
Copy link
Member

Scala 3 inherits these definitions while Scala 2 does not. This has generated… no small amount of confusion. :-) Basically the consequence of this is the fact that in any typeclass hierarchy which has one @implicitNotFound needs to have them on all classes.

@satorg
Copy link
Contributor Author

satorg commented Dec 1, 2021

Seems that Scala 2 also uses the inherited annotation (notice the sentence in parentheses):

could not find implicit value for parameter F: cats.ApplicativeError[Option,Int] (Could not find an instance of Applicative for Option)

But the overall error message is a way easier to decipher. At least it provides some clue where to start looking at.

@joroKr21
Copy link
Member

joroKr21 commented Dec 1, 2021

Why does Applicative need an @implicitNotFound with such a generic message? How is it different than the default?

@joroKr21
Copy link
Member

joroKr21 commented Dec 1, 2021

And is that an argument against inheritance of @implicitNotFound messages 🤔

@armanbilge
Copy link
Member

armanbilge commented Dec 1, 2021

Yes, I agree, I'm pretty sure we don't need these @implicitNotFound if the messages are so generic.

I experimented in a scastie (2.13) and it seems the default is to use the FQCN?
https://scastie.scala-lang.org/TUftkqyJSyyOg0XkkcntRw

trait Applicative[F[_]]
trait Foo[A]
implicitly[Applicative[Foo]]
// could not find implicit value for parameter e: Playground.Applicative[Playground.Foo]

Update: same on 2.12. Maybe some ancient scalac was much less friendly about these.

@armanbilge
Copy link
Member

Lol, apparently this inheritance issue was known at the time! #581 (comment)

(The bad part here is that I think this would require annotating every type class with some kind of message. Either that, or wiring it up to Simulacrum somehow.)

@joroKr21
Copy link
Member

joroKr21 commented Dec 1, 2021

Hmm so it's coming from simulacrum 🤔 , but the message never included the suggestion to import cats.implicits which is now obsolete anyway. 😄

@djspiewak
Copy link
Member

Let's just remove the annotations. I don't think they're carrying any weight.

@armanbilge
Copy link
Member

Does that mean making a change in simulacrum, and re-running it here? Not sure how that stuff works.

@djspiewak
Copy link
Member

We can just do it manually. Cats no longer uses simulacrum because the latter isn't compatible with Scala 3. Travis wrote a simulacrum-scalafix which kind of does the same thing, but I don't think it is run on an ongoing basis. I would need to check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issues that are easier to take on for first time contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants