Skip to content

Commit 26290f6

Browse files
oderskyWojciechMazur
authored andcommitted
Bring back ambiguity filter when we report an implicit not found error
This reverts one part of #20261. When we fail with both an ambiguity on one implicit argument and another error on another argument we prefer the other error. I added a comment why this is needed. Fixes #20344 [Cherry-picked 863077c]
1 parent 1c95cf0 commit 26290f6

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/Typer.scala

+8-1
Original file line numberDiff line numberDiff line change
@@ -3810,7 +3810,14 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
38103810
* `SearchFailureType`.
38113811
*/
38123812
def issueErrors(fun: Tree, args: List[Tree]): Tree =
3813-
def firstFailure = args.tpes.find(_.isInstanceOf[SearchFailureType]).getOrElse(NoType)
3813+
// Prefer other errors over ambiguities. If nested in outer searches a missing
3814+
// implicit can be healed by simply dropping this alternative and tryng something
3815+
// else. But an ambiguity is sticky and propagates outwards. If we have both
3816+
// a missing implicit on one argument and an ambiguity on another the whole
3817+
// branch should be classified as a missing implicit.
3818+
val firstNonAmbiguous = args.tpes.find(tp => tp.isError && !tp.isInstanceOf[AmbiguousImplicits])
3819+
def firstError = args.tpes.find(_.isInstanceOf[SearchFailureType]).getOrElse(NoType)
3820+
def firstFailure = firstNonAmbiguous.getOrElse(firstError)
38143821
val errorType =
38153822
firstFailure match
38163823
case tp: AmbiguousImplicits =>

Diff for: tests/pos/i20344.scala

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
trait Monad[F[_]] extends Invariant[F]
2+
3+
trait Invariant[F[_]]
4+
object Invariant:
5+
implicit def catsInstancesForList: Monad[List] = ???
6+
implicit def catsInstancesForVector: Monad[Vector] = ???
7+
8+
trait Shrink[T]
9+
object Shrink extends ShrinkLowPriorityImplicits:
10+
trait Buildable[T,C]
11+
implicit def shrinkContainer[C[_],T](implicit v: C[T] => Traversable[T], s: Shrink[T], b: Buildable[T,C[T]]): Shrink[C[T]] = ???
12+
trait ShrinkLowPriorityImplicits:
13+
implicit def shrinkAny[T]: Shrink[T] = ???
14+
15+
trait Distribution[F[_], -P, X] extends (P => F[X])
16+
type GenBeta[A, B, X] = [F[_]] =>> Distribution[F, Beta.Params[A, B], X]
17+
type Beta[R] = [F[_]] =>> GenBeta[R, R, R][F]
18+
19+
object Beta:
20+
trait Params[+A, +B]
21+
trait BetaInstances:
22+
given schrodingerRandomBetaForDouble[F[_]: Monad]: Beta[Double][F] = ???
23+
24+
object all extends BetaInstances
25+
26+
@main def Test =
27+
import all.given
28+
summon[Shrink[Beta.Params[Double, Double]]]

0 commit comments

Comments
 (0)