Skip to content

Commit 33f801b

Browse files
committed
Test extract from reactive-mongo
This will now be ambiguous.
1 parent bc26c51 commit 33f801b

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

tests/warn/bson.check

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- Warning: tests/warn/bson/Test.scala:5:60 ----------------------------------------------------------------------------
2+
5 |def typedMapHandler[K, V: BSONHandler] = stringMapHandler[V] // warn
3+
| ^
4+
|Given search preference for bson.BSONWriter[Map[String, V]] between alternatives (bson.BSONWriter.mapWriter : [V²](using x$1: bson.BSONWriter[V²]): bson.BSONDocumentWriter[Map[String, V²]]) and (bson.BSONWriter.collectionWriter :
5+
| [T, Repr <: Iterable[T]](using x$1: bson.BSONWriter[T], x$2: Repr ¬ Option[T]): bson.BSONWriter[Repr]) will change
6+
|Current choice : the first alternative
7+
|New choice from Scala 3.6: none - it's ambiguous
8+
|
9+
|where: V is a type in method typedMapHandler
10+
| V² is a type variable

tests/warn/bson/Test.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//> using options -source 3.5
2+
import bson.*
3+
4+
def stringMapHandler[V](using writer: BSONWriter[Map[String, V]]): BSONHandler[Map[String, V]] = ???
5+
def typedMapHandler[K, V: BSONHandler] = stringMapHandler[V] // warn

tests/warn/bson/bson.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package bson
2+
3+
trait BSONWriter[T]
4+
trait BSONDocumentWriter[T] extends BSONWriter[T]
5+
object BSONWriter extends BSONWriterInstances
6+
7+
trait BSONHandler[T] extends BSONWriter[T]
8+
9+
private[bson] trait BSONWriterInstances {
10+
given mapWriter[V](using BSONWriter[V]): BSONDocumentWriter[Map[String, V]] = bson.mapWriter[V]
11+
export bson.collectionWriter
12+
}
13+
14+
final class ¬[A, B]
15+
object ¬ {
16+
implicit def defaultEvidence[A, B]: ¬[A, B] = new ¬[A, B]()
17+
@annotation.implicitAmbiguous("Could not prove type ${A} is not (¬) ${A}")
18+
implicit def ambiguousEvidence1[A]: ¬[A, A] = null
19+
implicit def ambiguousEvidence2[A]: ¬[A, A] = null
20+
}
21+
22+
private[bson] trait DefaultBSONHandlers extends LowPriorityHandlers
23+
private[bson] trait LowPriorityHandlers{
24+
given collectionWriter[T, Repr <: Iterable[T]](using BSONWriter[T], Repr ¬ Option[T]): BSONWriter[Repr] = ???
25+
private[bson] def mapWriter[V](implicit valueWriter: BSONWriter[V]): BSONDocumentWriter[Map[String, V]] = ???
26+
}
27+
28+
// ---
29+
package object bson extends DefaultBSONHandlers

0 commit comments

Comments
 (0)