typelevel / typelevel/cats-time
Conflicting ContravariantShow for ZoneOffset
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 94
- Forks
- 19
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 3
Description
It seems my instances for ZoneId and ZoneOffset are slightly broken. When importing io.chrisdavenport.cats.time.instances.all._, I get a conflict when trying to show a ZoneOffset:
scala> show"${ZoneOffset.UTC}"
<console>:22: error: type mismatch;
found : java.time.ZoneOffset
required: cats.Show.Shown
show"${ZoneOffset.UTC}"
^
This arises because there are two overlapping instances for ContravariantShow[-T]:
scala> Show.Shown.mat(ZoneOffset.UTC)
<console>:22: error: ambiguous implicit values:
both value zoneidInstances in trait zoneid of type => cats.Show[java.time.ZoneId] with cats.Eq[java.time.ZoneId] with cats.Hash[java.time.ZoneId]
and value zoneoffsetInstances in trait zoneoffset of type => cats.Show[java.time.ZoneOffset] with cats.Order[java.time.ZoneOffset] with cats.Hash[java.time.ZoneOffset]
match expected type cats.Show.ContravariantShow[java.time.ZoneOffset]
Show.Shown.mat(ZoneOffset.UTC)
^
, and the compiler can't choose a better one.
I'm not sure what would be the best course of action here. Removing Show[ZoneOffset] would fix interpolation, however most of generic code I've seen relies directly on Show!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the instances exported by io.chrisdavenport.cats.time.instances.all._ and the ZoneId/ZoneOffset definitions; reproduce the ambiguity with Show.Shown.mat(ZoneOffset.UTC). Trace the two ContravariantShow candidates and determine an instance design that preserves generic Show use while making interpolation compile. Done means the reproduction compiles without an ambiguous implicit.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100