@@ -411,14 +411,14 @@ object Implicits:
411
411
412
412
/** A failed search */
413
413
case class SearchFailure (tree : Tree ) extends SearchResult {
414
- final def isAmbiguous : Boolean = tree.tpe.isInstanceOf [AmbiguousImplicits ]
414
+ final def isAmbiguous : Boolean = tree.tpe.isInstanceOf [AmbiguousImplicits | TooUnspecific ]
415
415
final def reason : SearchFailureType = tree.tpe.asInstanceOf [SearchFailureType ]
416
416
}
417
417
418
418
object SearchFailure {
419
419
def apply (tpe : SearchFailureType , span : Span )(using Context ): SearchFailure = {
420
420
val id = tpe match
421
- case tpe : AmbiguousImplicits =>
421
+ case tpe : ( AmbiguousImplicits | TooUnspecific ) =>
422
422
untpd.SearchFailureIdent (nme.AMBIGUOUS , s " /* ambiguous: ${tpe.explanation} */ " )
423
423
case _ =>
424
424
untpd.SearchFailureIdent (nme.MISSING , " /* missing */" )
@@ -504,11 +504,14 @@ object Implicits:
504
504
SearchFailure (ImplicitSearchTooLarge , NoSpan )(using NoContext )
505
505
506
506
/** A failure value indicating that an implicit search for a conversion was not tried */
507
- class TooUnspecific (target : Type ) extends NoMatchingImplicits (NoType , EmptyTree , OrderingConstraint .empty):
507
+ case class TooUnspecific (target : Type ) extends NoMatchingImplicits (NoType , EmptyTree , OrderingConstraint .empty):
508
508
override def whyNoConversion (using Context ): String =
509
509
i """
510
510
|Note that implicit conversions were not tried because the result of an implicit conversion
511
511
|must be more specific than $target"""
512
+ override def explanation (using Context ) =
513
+ i """ ${super .explanation}.
514
+ |The expected type $target is not specific enough, so no search was attempted """
512
515
override def toString = s " TooUnspecific "
513
516
514
517
/** An ambiguous implicits failure */
@@ -1484,7 +1487,7 @@ trait Implicits:
1484
1487
1485
1488
private def searchImplicit (contextual : Boolean ): SearchResult =
1486
1489
if isUnderspecified(wildProto) then
1487
- NoMatchingImplicitsFailure
1490
+ SearchFailure ( TooUnspecific (pt), span)
1488
1491
else
1489
1492
val eligible =
1490
1493
if contextual then
0 commit comments