Resolve ambigious implicits under new Scala 3.6 givens prioritization schema #415
+12
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Checklist
Test already existed
MacroSpec
from the logs below. Tested locally using nightly version of Scala 3 compiler:3.6.0-RC1-bin-20240718-bd84584-NIGHTLY
Fixes
Fixes usage of reactivemongo-bson for Scala 3.6+ users
Since Scala 3.5 or when using
-source:3.5
we'd get a warning:Since 3.6 it becomes a plain error about missing implicit
Purpose
This change resolves ambiguous implicit that are reported under the new givens prioritization betwen mapWriter and collectionWriter affecting Scala 3.6+ users.
It resolves compilation issues for the dependant projects mentioned here what the Scala 3 Open Community Build identified as failing due to the changes in compiler, especially https://github.com/lichess-org/lila and https://github.com/dapperware/dappermongo
Background Context
Since Scala 3.6 the order of givens prioritization have changed - compiler can choose the most general implicit instead of the most specific. For example when searching for
Writer[Map[String, T]]
mapWriter: BSONDocumentWriter[Map[String, V]]
instead ofcollectionWriter[T, Repr <: Iterable[T]]: BSONWriter[Repr]
as it's more specyficTo prevent this issue for Scala 3.6+ users more generalized writers should be put in the low-priority trait to workaround these changes. It would have no effect for Scala 3.5- users since the more specific implicit would choosen anyway
See Scala 3 PR that introduced this change for more info: scala/scala3#19300
I kindly request a timely release of a new version of ReactiveMongo-BSON after this change is merged to unblock dependant projects.