Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d33a968

Browse files
oderskyWojciechMazur
authored andcommittedJul 6, 2024
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 7da5b79 commit d33a968

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed
 

‎compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 8 additions & 1 deletion
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 =>

‎tests/pos/i20344.scala

Lines changed: 28 additions & 0 deletions
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)
Please sign in to comment.