-
Notifications
You must be signed in to change notification settings - Fork 26
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
Cats typeclass priority hierarchy #647
Conversation
Codecov Report
@@ Coverage Diff @@
## main #647 +/- ##
=======================================
Coverage 94.98% 94.98%
=======================================
Files 52 52
Lines 1793 1793
Branches 165 165
=======================================
Hits 1703 1703
Misses 90 90 |
|
||
class ScopeTest extends FunSuite { | ||
|
||
test("auto implicit will give most powerful abstraction") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how scala solves implicit conflicts.
In our case we could have only defined those as the other implicits methods can't be called explicitly due to the shapeless LowPriority
// use shapeless.LowPriority so the | ||
// provided cats type classes are always preferred | ||
// triggers derivation as last resort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we unfortunately have to keep shapeless.LowPriority
to avoid conflicts with implicits provided in cats._
// triggers derivation as last resort | ||
package object auto extends LowPriority0Implicits | ||
|
||
trait LowPriority0Implicits extends LowPriority2Implicits { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder how this worked before the fix. Wrong type class was picked up by compiler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the shapeless.LowPriority
got our back and was giving one of the implicit depending on the resolution.
implicitly[Group[Numbers]] | ||
implicitly[CommutativeGroup[Numbers]] | ||
implicitly[Show[Numbers]] | ||
val s: Show[Numbers] = implicitly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this a matter of style?
upd: Oh OK. I see it below
Respect cats typeclass hierarchy for implicit resolution as defined here
In practice, this was not creating any issue due to the usage of
shapeless.LowPriority
but intelliJ linter was showing conflicts in resolution.This fixes the lint errors and with scala 3, we'll have to define implicit priority properly anyway.
Tests were not run on the desired instance