Skip to content

Commit bc81563

Browse files
committed
Better implicit reporting under -explain-implicits
1 parent 1f75d92 commit bc81563

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class ScalaSettings extends Settings.SettingGroup {
2424
val deprecation = BooleanSetting("-deprecation", "Emit warning and location for usages of deprecated APIs.")
2525
val migration = BooleanSetting("-migration", "Emit warning and location for migration issues from Scala 2.")
2626
val encoding = StringSetting("-encoding", "encoding", "Specify character encoding used by source files.", Properties.sourceEncoding)
27-
val explaintypes = BooleanSetting("-explaintypes", "Explain type errors in more detail.")
27+
val explainTypes = BooleanSetting("-explain-types", "Explain type errors in more detail.")
28+
val explainImplicits = BooleanSetting("-explain-implicits", "Explain implicit search errors in more detail.")
2829
val explain = BooleanSetting("-explain", "Explain errors in more detail.")
2930
val feature = BooleanSetting("-feature", "Emit warning and location for usages of features that should be imported explicitly.")
3031
val help = BooleanSetting("-help", "Print a synopsis of standard options")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ object ErrorReporting {
114114
val expected1 = dropJavaMethod(expected)
115115
if ((found1 eq found) != (expected eq expected1) && (found1 <:< expected1))
116116
"\n (Note that Scala's and Java's representation of this type differs)"
117-
else if (ctx.settings.explaintypes.value)
117+
else if (ctx.settings.explainTypes.value)
118118
"\n" + ctx.typerState.show + "\n" + TypeComparer.explained((found <:< expected)(_))
119119
else
120120
""

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,14 @@ object Implicits {
334334
class FailedImplicit(failures: List[ExplainedSearchFailure], val pt: Type, val argument: tpd.Tree) extends ExplainedSearchFailure {
335335
def explanation(implicit ctx: Context): String =
336336
if (failures.isEmpty) s" No implicit candidates were found that $qualify"
337-
else " " + (failures map (_.explanation) mkString "\n ")
338-
override def postscript(implicit ctx: Context): String =
337+
else failures.map(_.explanation).mkString("\n").replace("\n", "\n ")
338+
override def postscript(implicit ctx: Context): String = {
339+
val what =
340+
if (argument.isEmpty) i"value of type $pt"
341+
else i"conversion from ${argument.tpe.widen} to $pt"
339342
i"""
340-
|Implicit search failure summary:
341343
|$explanation"""
344+
}
342345
}
343346
}
344347

@@ -671,7 +674,7 @@ trait Implicits { self: Typer =>
671674
ctx.traceIndented(s"search implicit ${pt.show}, arg = ${argument.show}: ${argument.tpe.show}", implicits, show = true) {
672675
assert(!pt.isInstanceOf[ExprType])
673676
val isearch =
674-
if (ctx.settings.explaintypes.value) new ExplainedImplicitSearch(pt, argument, pos)
677+
if (ctx.settings.explainImplicits.value) new ExplainedImplicitSearch(pt, argument, pos)
675678
else new ImplicitSearch(pt, argument, pos)
676679
val result = isearch.bestImplicit
677680
result match {

0 commit comments

Comments
 (0)