Skip to content

Commit 2c4ec50

Browse files
committed
Fix #10709: Add missing level check before inlining
If an a call to an inline method is within a quote, this call must not be inlined.
1 parent 3c18f6b commit 2c4ec50

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-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
@@ -3293,7 +3293,7 @@ class Typer extends Namer
32933293
}
32943294
else if (methPart(tree).symbol.isAllOf(Inline | Deferred) && !Inliner.inInlineMethod) then
32953295
errorTree(tree, i"Deferred inline ${methPart(tree).symbol.showLocated} cannot be invoked")
3296-
else if (Inliner.isInlineable(tree) && !suppressInline) {
3296+
else if (Inliner.isInlineable(tree) && !suppressInline && StagingContext.level == 0) {
32973297
tree.tpe <:< wildApprox(pt)
32983298
val errorCount = ctx.reporter.errorCount
32993299
val meth = methPart(tree).symbol

tests/neg-macros/i10709/Macro_1.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import scala.quoted._
2+
import scala.compiletime.summonInline
3+
4+
object Invalid {
5+
inline def apply[A, B]: Any = ${ invalidImpl[A, B] }
6+
7+
def invalidImpl[A, B](using qctx: Quotes, tpeA: Type[A], tpeB: Type[B]): Expr[Any] = {
8+
'{summonInline[B <:< A]}
9+
}
10+
}

tests/neg-macros/i10709/Test_2.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class A
2+
class B extends A
3+
4+
def test: Unit =
5+
println(Invalid[A, B]) // compiles as expected
6+
println(Invalid[B, A]) // error

0 commit comments

Comments
 (0)