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

Id instances cannot be removed from the scope #2276

Closed
djspiewak opened this issue Jun 2, 2018 · 5 comments
Closed

Id instances cannot be removed from the scope #2276

djspiewak opened this issue Jun 2, 2018 · 5 comments

Comments

@djspiewak
Copy link
Member

This is the best thing ever:

cats.Monad[cats.Id]

No imports. That compiles. Credit to @edmundnoble for finding the original issue here: djspiewak/shims#20

The problem here is that catsInstancesForId is defined in the cats package object. This is a problem because the cats package is a component of the cats.Id type, and the cats package object is its own companion, meaning that the cats package object part of the implicit scope (without any imports!) used when resolving any type in the cats package (or presumably, any subpackage). This would also be a problem if other implicits were defined in the cats package object, but the Id instances are the only ones.

As far as I can tell, this scoping issue is pretty innocuous (if a bit leaky) if you're only using cats. Unfortunately, the moment you have scalaz on the classpath (you don't even need imports!) and are using shims, you end up in a world of hurt. See the issue I linked for an example.

The solution here is to unfortunately break compatibility. Implicits should be banned from the cats package object, and the Id instances should be moved to something like cats.implicits.id.

@kailuowang
Copy link
Contributor

Thanks for reporting this. Do you mind provide a bit more specifics on how this hurts people with scalaz in class path? I mean all data types defined in cats have instances defined in companion objects and thus in scope without imports. I understand Id is special but curious how it affects differently in this scenario. Thanks!

@johnynek
Copy link
Contributor

johnynek commented Jun 2, 2018

Actually removing implicit annotation is Mima compatible. So, we could keep the vals/defs but remove implicit.

@djspiewak
Copy link
Member Author

djspiewak commented Jun 2, 2018

@johnynek Oh good call! Not source compatible, but binary.

@kailuowang It affects people in the scalaz namespace (as scalaz affects people in the cats namespace) as described in the linked shims ticket. It appears that the compiler considers both Id types to be equivalent by some notion of compatibility when viewed through the shims implicit mechanisms. This may be a bug in scalac, I’m not sure. But the net result is that scalaz and cats having this problem results in ambiguities for the other when shims is in scope, since shims makes instances for each equivalent to the other.

@kailuowang
Copy link
Contributor

Thanks for detail @djspiewak

@armanbilge
Copy link
Member

As far as I can tell, this scoping issue is pretty innocuous (if a bit leaky) if you're only using cats.

I'd say that's a safe assumption nowadays.

@armanbilge armanbilge closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants