Skip to content

Commit 98c4b7d

Browse files
committed
Fix handling divergent implicits
If we hit a divergent implicit during a contextual search, we should continue with a type-based search. Only ambiguities are globally fatal. The removed test that prevented this logic was introduced when I experimented with fatal divergence. It was left in by oversight.
1 parent 03779a1 commit 98c4b7d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ trait Implicits { self: Typer =>
991991
else implicitScope(wildProto).eligible
992992
searchImplicits(eligible, contextual).recoverWith {
993993
failure => failure.reason match {
994-
case (_: AmbiguousImplicits) | (_: DivergingImplicit) => failure
994+
case _: AmbiguousImplicits => failure
995995
case _ => if (contextual) bestImplicit(contextual = false) else failure
996996
}
997997
}

tests/pos/implicit-divergent.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Foo[T]
2+
object Foo {
3+
implicit def intFoo: Foo[Int] = ???
4+
}
5+
6+
object Test {
7+
implicit def genFoo[T](implicit f: Foo[T => T]): Foo[T] = ???
8+
9+
def test: Unit = {
10+
implicitly[Foo[Int]]
11+
}
12+
}

0 commit comments

Comments
 (0)