Skip to content
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

Bring back ambiguity filter when we report an implicit not found error #20368

Merged
merged 2 commits into from
May 8, 2024
Merged
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
9 changes: 8 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4113,7 +4113,14 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
* `SearchFailureType`.
*/
def issueErrors(fun: Tree, args: List[Tree]): Tree =
def firstFailure = args.tpes.find(_.isInstanceOf[SearchFailureType]).getOrElse(NoType)
// Prefer other errors over ambiguities. If nested in outer searches a missing
// implicit can be healed by simply dropping this alternative and trying something
// else. But an ambiguity is sticky and propagates outwards. If we have both
// a missing implicit on one argument and an ambiguity on another the whole
// branch should be classified as a missing implicit.
val firstNonAmbiguous = args.tpes.find(tp => tp.isError && !tp.isInstanceOf[AmbiguousImplicits])
def firstError = args.tpes.find(_.isInstanceOf[SearchFailureType]).getOrElse(NoType)
def firstFailure = firstNonAmbiguous.getOrElse(firstError)
val errorType =
firstFailure match
case tp: AmbiguousImplicits =>
Expand Down
28 changes: 28 additions & 0 deletions tests/pos/i20344.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
trait Monad[F[_]] extends Invariant[F]

trait Invariant[F[_]]
object Invariant:
implicit def catsInstancesForList: Monad[List] = ???
implicit def catsInstancesForVector: Monad[Vector] = ???

trait Shrink[T]
object Shrink extends ShrinkLowPriorityImplicits:
trait Buildable[T,C]
implicit def shrinkContainer[C[_],T](implicit v: C[T] => Traversable[T], s: Shrink[T], b: Buildable[T,C[T]]): Shrink[C[T]] = ???
trait ShrinkLowPriorityImplicits:
implicit def shrinkAny[T]: Shrink[T] = ???

trait Distribution[F[_], -P, X] extends (P => F[X])
type GenBeta[A, B, X] = [F[_]] =>> Distribution[F, Beta.Params[A, B], X]
type Beta[R] = [F[_]] =>> GenBeta[R, R, R][F]

object Beta:
trait Params[+A, +B]
trait BetaInstances:
given schrodingerRandomBetaForDouble[F[_]: Monad]: Beta[Double][F] = ???

object all extends BetaInstances

@main def Test =
import all.given
summon[Shrink[Beta.Params[Double, Double]]]
Loading