@@ -440,7 +440,7 @@ object Implicits:
440
440
}
441
441
}
442
442
443
- abstract class SearchFailureType extends ErrorType {
443
+ abstract class SearchFailureType extends ErrorType , Addenda {
444
444
def expectedType : Type
445
445
def argument : Tree
446
446
@@ -457,11 +457,6 @@ object Implicits:
457
457
if (argument.isEmpty) i " match type ${clarify(expectedType)}"
458
458
else i " convert from ${argument.tpe} to ${clarify(expectedType)}"
459
459
}
460
-
461
- /** If search was for an implicit conversion, a note describing the failure
462
- * in more detail - this is either empty or starts with a '\n'
463
- */
464
- def whyNoConversion (using Context ): String = " "
465
460
}
466
461
467
462
class NoMatchingImplicits (val expectedType : Type , val argument : Tree , constraint : Constraint = OrderingConstraint .empty)
@@ -515,33 +510,38 @@ object Implicits:
515
510
516
511
/** A failure value indicating that an implicit search for a conversion was not tried */
517
512
case class TooUnspecific (target : Type ) extends NoMatchingImplicits (NoType , EmptyTree , OrderingConstraint .empty):
518
- override def whyNoConversion (using Context ): String =
513
+
514
+ override def toAdd (using Context ) =
519
515
i """
520
516
|Note that implicit conversions were not tried because the result of an implicit conversion
521
- |must be more specific than $target"""
517
+ |must be more specific than $target""" :: Nil
522
518
523
519
override def msg (using Context ) =
524
520
super .msg.append(" \n The expected type $target is not specific enough, so no search was attempted" )
521
+
525
522
override def toString = s " TooUnspecific "
523
+ end TooUnspecific
526
524
527
525
/** An ambiguous implicits failure */
528
- class AmbiguousImplicits (val alt1 : SearchSuccess , val alt2 : SearchSuccess , val expectedType : Type , val argument : Tree ) extends SearchFailureType {
526
+ class AmbiguousImplicits (val alt1 : SearchSuccess , val alt2 : SearchSuccess , val expectedType : Type , val argument : Tree ) extends SearchFailureType :
527
+
529
528
def msg (using Context ): Message =
530
529
var str1 = err.refStr(alt1.ref)
531
530
var str2 = err.refStr(alt2.ref)
532
531
if str1 == str2 then
533
532
str1 = ctx.printer.toTextRef(alt1.ref).show
534
533
str2 = ctx.printer.toTextRef(alt2.ref).show
535
534
em " both $str1 and $str2 $qualify" .withoutDisambiguation()
536
- override def whyNoConversion (using Context ): String =
535
+
536
+ override def toAdd (using Context ) =
537
537
if ! argument.isEmpty && argument.tpe.widen.isRef(defn.NothingClass ) then
538
- " "
538
+ Nil
539
539
else
540
540
val what = if (expectedType.isInstanceOf [SelectionProto ]) " extension methods" else " conversions"
541
541
i """
542
542
|Note that implicit $what cannot be applied because they are ambiguous;
543
- | $explanation"""
544
- }
543
+ | $explanation""" :: Nil
544
+ end AmbiguousImplicits
545
545
546
546
class MismatchedImplicit (ref : TermRef ,
547
547
val expectedType : Type ,
0 commit comments