From 45edfb018886f7d53de7c27280d66bedd4e29164 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 22 Jun 2020 16:47:42 +0200 Subject: [PATCH] Fix #9014: On implicit search failure print original inline call This it is possible to copy/paste the original call that failed and get the error message. --- compiler/src/dotty/tools/dotc/typer/Implicits.scala | 6 +++++- tests/neg-macros/i9014.check | 10 ++++++++++ tests/neg-macros/i9014/Macros_1.scala | 4 ++++ tests/neg-macros/i9014/Test_2.scala | 1 + tests/neg/i9014.check | 9 +++++++++ tests/neg/i9014.scala | 4 ++++ 6 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/neg-macros/i9014.check create mode 100644 tests/neg-macros/i9014/Macros_1.scala create mode 100644 tests/neg-macros/i9014/Test_2.scala create mode 100644 tests/neg/i9014.check create mode 100644 tests/neg/i9014.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index 1eaf226dfe90..845ca7a95eec 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -786,10 +786,14 @@ trait Implicits { self: Typer => case _ => arg.tpe match { case tpe: SearchFailureType => + val original = arg match + case Inlined(call, _, _) => call + case _ => arg + i"""$headline. |I found: | - | ${arg.show.replace("\n", "\n ")} + | ${original.show.replace("\n", "\n ")} | |But ${tpe.explanation}.""" } diff --git a/tests/neg-macros/i9014.check b/tests/neg-macros/i9014.check new file mode 100644 index 000000000000..563152f76ee0 --- /dev/null +++ b/tests/neg-macros/i9014.check @@ -0,0 +1,10 @@ + +-- Error: tests/neg-macros/i9014/Test_2.scala:1:23 --------------------------------------------------------------------- +1 |val tests = summon[Bar] // error + | ^ + | no implicit argument of type Bar was found for parameter x of method summon in object DottyPredef. + | I found: + | + | given_Bar + | + | But method given_Bar does not match type Bar. diff --git a/tests/neg-macros/i9014/Macros_1.scala b/tests/neg-macros/i9014/Macros_1.scala new file mode 100644 index 000000000000..eec8af992b1c --- /dev/null +++ b/tests/neg-macros/i9014/Macros_1.scala @@ -0,0 +1,4 @@ +import scala.quoted._ +trait Bar +inline given as Bar = ${ impl } +def impl(using qctx: QuoteContext): Expr[Bar] = qctx.throwError("Failed to expand!") diff --git a/tests/neg-macros/i9014/Test_2.scala b/tests/neg-macros/i9014/Test_2.scala new file mode 100644 index 000000000000..b23781947922 --- /dev/null +++ b/tests/neg-macros/i9014/Test_2.scala @@ -0,0 +1 @@ +val tests = summon[Bar] // error diff --git a/tests/neg/i9014.check b/tests/neg/i9014.check new file mode 100644 index 000000000000..74d5d7f05cfe --- /dev/null +++ b/tests/neg/i9014.check @@ -0,0 +1,9 @@ +-- Error: tests/neg/i9014.scala:4:25 ----------------------------------------------------------------------------------- +4 | val tests = summon[Bar] // error + | ^ + | no implicit argument of type Bar was found for parameter x of method summon in object DottyPredef. + | I found: + | + | Bar.given_Bar + | + | But method given_Bar in object Bar does not match type Bar. diff --git a/tests/neg/i9014.scala b/tests/neg/i9014.scala new file mode 100644 index 000000000000..827e111d6116 --- /dev/null +++ b/tests/neg/i9014.scala @@ -0,0 +1,4 @@ +trait Bar +object Bar: + inline given as Bar = compiletime.error("Failed to expand!") + val tests = summon[Bar] // error