Skip to content

Only report changes in given priority when disambiguating #21046

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1320,14 +1320,14 @@ trait Implicits:
* 3.6 and higher: compare with preferGeneral = true
*
*/
def compareAlternatives(alt1: RefAndLevel, alt2: RefAndLevel): Int =
def compareAlternatives(alt1: RefAndLevel, alt2: RefAndLevel, reportChanges: Boolean = false): Int =
def comp(using Context) = explore(compare(alt1.ref, alt2.ref, preferGeneral = true))
def warn(msg: Message) =
priorityChangeWarnings += ((alt1.ref, alt2.ref, msg))
if reportChanges then priorityChangeWarnings += ((alt1.ref, alt2.ref, msg))
if alt1.ref eq alt2.ref then 0
else if alt1.level != alt2.level then alt1.level - alt2.level
else
var cmp = comp(using searchContext())
val cmp = comp(using searchContext())
val sv = Feature.sourceVersion
if sv.stable == SourceVersion.`3.5` || sv == SourceVersion.`3.6-migration` then
val prev = comp(using searchContext().addMode(Mode.OldImplicitResolution))
Expand Down Expand Up @@ -1358,7 +1358,7 @@ trait Implicits:
*/
def disambiguate(alt1: SearchResult, alt2: SearchSuccess) = alt1 match
case alt1: SearchSuccess =>
var diff = compareAlternatives(alt1, alt2)
var diff = compareAlternatives(alt1, alt2, reportChanges = true)
assert(diff <= 0) // diff > 0 candidates should already have been eliminated in `rank`
if diff == 0 && alt1.ref =:= alt2.ref then
diff = 1 // See i12951 for a test where this happens
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/given-triangle.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- [E172] Type Error: tests/neg/given-triangle.scala:14:18 -------------------------------------------------------------
14 |@main def Test = f // error
| ^
|Ambiguous given instances: both given instance given_B and given instance given_C match type A of parameter a of method f
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//> using options -source 3.6-migration

class A
class B extends A
class C extends A
Expand All @@ -13,4 +11,4 @@ def f(using a: A, b: B, c: C) =
println(b.getClass)
println(c.getClass)

@main def Test = f // warn
@main def Test = f // error
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions tests/pos/i20572.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//> using options -Werror
trait Writes[T]
trait Format[T] extends Writes[T]
given [T: List]: Writes[T] = null
given [T]: Format[T] = null

val _ = summon[Writes[Int]]
16 changes: 16 additions & 0 deletions tests/pos/i21036.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//> using options -source 3.5 -Werror
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] = ???

val x = summon[BSONHandler[List[Id]]] // this doesn't emit warning
val y = summon[BSONWriter[List[Id]]] // this did emit warning
2 changes: 1 addition & 1 deletion tests/run/given-triangle.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import language.future
import language.`3.6`

class A
class B extends A
Expand Down
10 changes: 0 additions & 10 deletions tests/warn/bson.check

This file was deleted.

6 changes: 0 additions & 6 deletions tests/warn/given-triangle.check

This file was deleted.

Loading