Skip to content

False positive warning for new implicit resolution rules in 3.5.0-RC3 #21036

Closed
@lenguyenthanh

Description

@lenguyenthanh

Compiler version

3.5.0-RC3

Minimized code

//> using scala 3.5.0-RC3
// //> using options -source:3.6-migration

trait SameRuntime[A, B]
trait BSONWriter[T]
trait BSONHandler[T] extends BSONWriter[T]

opaque type Id = String
object Id:
  given SameRuntime[Id, String] = ???

given BSONHandler[String]                    = ???
given [T: BSONHandler]: BSONHandler[List[T]] = ???

given opaqueWriter[T, A](using
    rs: SameRuntime[T, A],
    writer: BSONWriter[A]
): BSONWriter[T] = ???

def write[A](a: A)(using writer: BSONWriter[A]): Unit = ???

val ids: List[Id] = ???

val x = write(ids)

Output

[warn] ./ImplicitResolution2.scala:24:19
[warn] Given search preference for BSONWriter[List[Id]] between alternatives (given_BSONHandler_List :
[warn]   [T](implicit evidence$1: BSONHandler[T]): BSONHandler[List[T]]) and (opaqueWriter :
[warn]   [T, A](using rs: SameRuntime[T, A], writer: BSONWriter[A]): BSONWriter[T]) will change
[warn] Current choice           : the first alternative
[warn] New choice from Scala 3.6: none - it's ambiguous
[warn] val x = write(ids)
[warn]                   ^
Compiled project (Scala 3.5.0-RC3, JVM (21))

Expectation

It shouldn't emit any warnings, as there is no implicit evidence for the second case. Also if we enabled //> using options -source:3.6-migration it works perfectly.

Related discussions: #19300 and #20484

Metadata

Metadata

Labels

area:implicitsrelated to implicitsarea:reportingError reporting including formatting, implicit suggestions, etcarea:typeritype:bugprio:highregressionThis worked in a previous version but doesn't anymore

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions