-
-
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
Issue 2657 - Ambiguous duration instances #2670
Conversation
@@ -9,12 +9,12 @@ package object instances { | |||
object byte extends ByteInstances | |||
object char extends CharInstances | |||
object double extends DoubleInstances | |||
object duration extends DurationInstances | |||
object duration extends CoreDurationInstances with DurationInstances |
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'm still trying to solve an issue here as importing both cats.instances.duration._
and cats.instances.finiteDuration._
explicitly prevents for the instance to be resolved. The scenario is when there's the need for kernel instances together with core's
object test {
import cats.instances.duration._
import cats.instances.finiteDuration._
implicitly[Order[Duration]]
implicitly[ContravariantShow[FiniteDuration]]
}
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 why we don't have variance in type classes. I'd say in this case user have to use workarounds.
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 found a way to mitigate the problem. Now the only case that would fail is the below (see these test cases as an example).
test("fails") {
import cats.instances.duration._
import cats.instances.finiteDuration._
implicitly[ContravariantShow[Duration]] // fails compilation
implicitly[ContravariantShow[FiniteDuration]] // is inferred
}
I couldn't find a way to remove also this drawback.
Codecov Report
@@ Coverage Diff @@
## master #2670 +/- ##
==========================================
+ Coverage 95.12% 95.13% +<.01%
==========================================
Files 364 365 +1
Lines 6707 6756 +49
Branches 285 300 +15
==========================================
+ Hits 6380 6427 +47
- Misses 327 329 +2
Continue to review full report at Codecov.
|
I don't think I can do more here without breaking the BC. It's anyway a step forward compared to the current situation. If you agree, I would consider this PR complete. |
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.
Thanks very much @barambani :)
👍 |
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.
Thanks a lot! @barambani
👍 |
This is to address #2657