From 4f87b5aa821450a72a0a21aa2239f0e6324bbd4b Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 2 Jul 2019 15:37:38 +0200 Subject: [PATCH] Fix #6783: Check all owner to detect if inside an `inline` method --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- tests/neg/i6783.scala | 7 +++++++ tests/pos/i6783.scala | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i6783.scala create mode 100644 tests/pos/i6783.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index faff91716c4a..b3388f51fe6c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2082,7 +2082,7 @@ class Typer extends Namer } private def checkSpliceOutsideQuote(tree: untpd.Tree)(implicit ctx: Context): Unit = { - if (level == 0 && !ctx.owner.isInlineMethod) + if (level == 0 && !ctx.owner.ownersIterator.exists(_.is(Inline))) ctx.error("Splice ${...} outside quotes '{...} or inline method", tree.sourcePos) else if (level < 0) ctx.error( diff --git a/tests/neg/i6783.scala b/tests/neg/i6783.scala new file mode 100644 index 000000000000..55af88234692 --- /dev/null +++ b/tests/neg/i6783.scala @@ -0,0 +1,7 @@ +import scala.quoted._ + +inline def test(f: (Int, Int) => Int) = ${ // error: Malformed macro + testImpl((a: Expr[Int], b: Expr[Int]) => '{ f(${a}, ${b}) }) +} + +def testImpl(f: (Expr[Int], Expr[Int]) => Expr[Int]): Expr[Int] = ??? diff --git a/tests/pos/i6783.scala b/tests/pos/i6783.scala new file mode 100644 index 000000000000..e8945ec135be --- /dev/null +++ b/tests/pos/i6783.scala @@ -0,0 +1,7 @@ +import scala.quoted._ + +def testImpl(f: Expr[(Int, Int) => Int]): Expr[Int] = f('{1}, '{2}) + +inline def test(f: (Int, Int) => Int) = ${ + testImpl('f) +}