Skip to content

Commit 429c0a4

Browse files
committed
Fix #4431: Disallow macro parameters that are inline functions
1 parent 6f6816d commit 429c0a4

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,10 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
604604
""".stripMargin, tree.rhs.pos)
605605
EmptyTree
606606
}
607+
case tree: ValDef if tree.symbol.is(Param | Inline) && tree.symbol.owner.is(Macro) &&
608+
defn.isFunctionClass(tree.tpe.widen.typeSymbol) =>
609+
ctx.error("Macro parameters of function type cannot be `inline`", tree.pos)
610+
EmptyTree
607611
case _ =>
608612
markDef(tree)
609613
checkLevel(mapOverTree(enteredSyms))

tests/neg/i4431.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
object Foo {
3+
inline def h(inline f: Int => String): String = ~ '(f(42)) // error
4+
}

tests/neg/i4433.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
object Foo {
3+
inline def g(inline p: Int => Boolean): Boolean = ~{ // error
4+
if(p(5)) '(true)
5+
else '(false)
6+
}
7+
}

0 commit comments

Comments
 (0)