Skip to content

Commit f5b6463

Browse files
committed
Pick most significant error in implicit search
In implicit search, if both contextual and type search fail, pick the more significant error of the two searches to report. - ambiguous trumps other errors - otherwise, errors with larger computed results trump errors with smaller ones.
1 parent f0c1894 commit f5b6463

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ object Implicits {
9595
def methodCandidateKind(mt: MethodType, approx: Boolean) =
9696
if (mt.isImplicitMethod)
9797
viewCandidateKind(normalize(mt, pt), argType, resType)
98-
else if (!mt.isImplicitMethod &&
99-
mt.paramInfos.lengthCompare(1) == 0 && {
98+
else if (mt.paramInfos.lengthCompare(1) == 0 && {
10099
var formal = widenSingleton(mt.paramInfos.head)
101100
if (approx) formal = wildApprox(formal)
102101
ctx.test(implicit ctx => argType relaxed_<:< formal)
@@ -1276,9 +1275,13 @@ trait Implicits { self: Typer =>
12761275
case reason =>
12771276
if (contextual)
12781277
bestImplicit(contextual = false).recoverWith {
1279-
failure2 => reason match {
1280-
case (_: DivergingImplicit) | (_: ShadowedImplicit) => failure
1281-
case _ => failure2
1278+
failure2 => failure2.reason match {
1279+
case _: AmbiguousImplicits => failure2
1280+
case _ =>
1281+
reason match {
1282+
case (_: DivergingImplicit) | (_: ShadowedImplicit) => failure
1283+
case _ => List(failure, failure2).maxBy(_.tree.treeSize)
1284+
}
12821285
}
12831286
}
12841287
else failure
@@ -1637,4 +1640,6 @@ final class TermRefSet(implicit ctx: Context) {
16371640
foreach(tr => buffer += tr)
16381641
buffer.toList
16391642
}
1643+
1644+
override def toString = toList.toString
16401645
}

0 commit comments

Comments
 (0)