Skip to content

Commit ea13cad

Browse files
committed
Search for Conversions if implicit search fails
1 parent d6cc101 commit ea13cad

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

compiler/src/dotty/tools/dotc/reporting/messages.scala

+7-1
Original file line numberDiff line numberDiff line change
@@ -2554,7 +2554,8 @@ class MissingImplicitArgument(
25542554
pt: Type,
25552555
where: String,
25562556
paramSymWithMethodCallTree: Option[(Symbol, tpd.Tree)] = None,
2557-
ignoredInstanceNormalImport: => Option[SearchSuccess]
2557+
ignoredInstanceNormalImport: => Option[SearchSuccess],
2558+
ignoredConversions: => Set[SearchSuccess]
25582559
)(using Context) extends TypeMsg(MissingImplicitArgumentID), ShowMatchTrace(pt):
25592560

25602561
arg.tpe match
@@ -2743,8 +2744,13 @@ class MissingImplicitArgument(
27432744
// show all available additional info
27442745
def hiddenImplicitNote(s: SearchSuccess) =
27452746
i"\n\nNote: ${s.ref.symbol.showLocated} was not considered because it was not imported with `import given`."
2747+
def noChainConversionsNote(s: Set[SearchSuccess]): Option[String] =
2748+
Option.when(s.isEmpty)(
2749+
i"\n\nNote: Chaining implicit conversions is no longer allowed in Scala. The following conversions were ignored: ${s.map(_.ref.symbol.showLocated).mkString("\n")}"
2750+
)
27462751
super.msgPostscript
27472752
++ ignoredInstanceNormalImport.map(hiddenImplicitNote)
2753+
.orElse(noChainConversionsNote(ignoredConversions))
27482754
.getOrElse(ctx.typer.importSuggestionAddendum(pt))
27492755

27502756
def explain(using Context) = ""

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,14 @@ trait Implicits:
923923
// example where searching for a nested type causes an infinite loop.
924924
None
925925

926-
MissingImplicitArgument(arg, pt, where, paramSymWithMethodCallTree, ignoredInstanceNormalImport)
926+
def ignoredConversions = arg.tpe match
927+
case fail: SearchFailureType =>
928+
if (fail.expectedType eq pt) || isFullyDefined(fail.expectedType, ForceDegree.none) then
929+
ImplicitSearch(fail.expectedType, dummyTreeOfType(WildcardType), arg.span).allImplicits
930+
else
931+
Set.empty
932+
933+
MissingImplicitArgument(arg, pt, where, paramSymWithMethodCallTree, ignoredInstanceNormalImport, ignoredConversions)
927934
}
928935

929936
/** A string indicating the formal parameter corresponding to a missing argument */

0 commit comments

Comments
 (0)