Skip to content

Commit 1cec6a9

Browse files
Merge pull request #6788 from dotty-staging/fix-#6783
Fix #6783: Check all owner to detect if inside an `inline` method
2 parents 4a107cc + 4f87b5a commit 1cec6a9

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2259,7 +2259,7 @@ class Typer extends Namer
22592259
}
22602260

22612261
private def checkSpliceOutsideQuote(tree: untpd.Tree)(implicit ctx: Context): Unit = {
2262-
if (level == 0 && !ctx.owner.isInlineMethod)
2262+
if (level == 0 && !ctx.owner.ownersIterator.exists(_.is(Inline)))
22632263
ctx.error("Splice ${...} outside quotes '{...} or inline method", tree.sourcePos)
22642264
else if (level < 0)
22652265
ctx.error(

tests/neg/i6783.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.quoted._
2+
3+
inline def test(f: (Int, Int) => Int) = ${ // error: Malformed macro
4+
testImpl((a: Expr[Int], b: Expr[Int]) => '{ f(${a}, ${b}) })
5+
}
6+
7+
def testImpl(f: (Expr[Int], Expr[Int]) => Expr[Int]): Expr[Int] = ???

tests/pos/i6783.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.quoted._
2+
3+
def testImpl(f: Expr[(Int, Int) => Int]): Expr[Int] = f('{1}, '{2})
4+
5+
inline def test(f: (Int, Int) => Int) = ${
6+
testImpl('f)
7+
}

0 commit comments

Comments
 (0)