From 8cbec9218f80e8ab7cc7a7103659617a3edfd05d Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 12 May 2020 15:05:56 +0200 Subject: [PATCH] Fix #7839: Improve error message for implicit parameters --- compiler/src/dotty/tools/dotc/transform/Splicer.scala | 6 +++--- tests/neg-macros/i7839.check | 8 ++++++++ tests/neg-macros/i7839.scala | 6 ++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 tests/neg-macros/i7839.check create mode 100644 tests/neg-macros/i7839.scala diff --git a/compiler/src/dotty/tools/dotc/transform/Splicer.scala b/compiler/src/dotty/tools/dotc/transform/Splicer.scala index 2e535d58d0e3..38c38ac42eff 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicer.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicer.scala @@ -160,12 +160,12 @@ object Splicer { // OK case _ => + val extra = if tree.span.isZeroExtent then ": " + tree.show else "" ctx.error( - """Malformed macro parameter + s"""Malformed macro parameter$extra | - |Parameters may be: + |Parameters may only be: | * Quoted parameters or fields - | * References to inline parameters | * Literal values of primitive types |""".stripMargin, tree.sourcePos) } diff --git a/tests/neg-macros/i7839.check b/tests/neg-macros/i7839.check new file mode 100644 index 000000000000..197867ab809b --- /dev/null +++ b/tests/neg-macros/i7839.check @@ -0,0 +1,8 @@ +-- Error: tests/neg-macros/i7839.scala:4:18 ---------------------------------------------------------------------------- +4 | ${ transformImpl } // error + | ^ + | Malformed macro parameter: dummyImplicit + | + | Parameters may only be: + | * Quoted parameters or fields + | * Literal values of primitive types diff --git a/tests/neg-macros/i7839.scala b/tests/neg-macros/i7839.scala new file mode 100644 index 000000000000..60536771b2bd --- /dev/null +++ b/tests/neg-macros/i7839.scala @@ -0,0 +1,6 @@ +import scala.quoted._ + +inline def transform(using dummyImplicit: DummyImplicit): Unit = + ${ transformImpl } // error + +def transformImpl(using dummyImplicit: DummyImplicit)(using QuoteContext): Expr[Unit] = ???