-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Comments
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! |
Actually removing implicit annotation is Mima compatible. So, we could keep the vals/defs but remove implicit. |
@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. |
Thanks for detail @djspiewak |
I'd say that's a safe assumption nowadays. |
This is the best thing ever:
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 thecats
package object. This is a problem because thecats
package is a component of thecats.Id
type, and thecats
package object is its own companion, meaning that thecats
package object part of the implicit scope (without any imports!) used when resolving any type in thecats
package (or presumably, any subpackage). This would also be a problem if other implicits were defined in thecats
package object, but theId
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 theId
instances should be moved to something likecats.implicits.id
.The text was updated successfully, but these errors were encountered: