Skip to content

Commit 5ed0845

Browse files
committed
Set the correct owner when quote making inlinable
Fixes #13546
1 parent dd6da26 commit 5ed0845

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ trait QuotesAndSplices {
7070
}
7171

7272
private def makeInlineable(tree: Tree)(using Context): Tree =
73-
ctx.compilationUnit.inlineAccessors.makeInlineable(tree)
73+
def quoteOwner(sym: Symbol): Symbol =
74+
if sym.owner.isClass then sym else quoteOwner(sym.owner)
75+
inContext(ctx.withOwner(quoteOwner(ctx.owner))) {
76+
ctx.compilationUnit.inlineAccessors.makeInlineable(tree)
77+
}
78+
7479

7580
/** Translate `${ t: Expr[T] }` into expression `t.splice` while tracking the quotation level in the context */
7681
def typedSplice(tree: untpd.Splice, pt: Type)(using Context): Tree = {
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package mylib
2+
import scala.quoted.*
3+
4+
object Main:
5+
protected def foo: Unit = {}
6+
inline def fooCaller: Unit =
7+
def f = foo
8+
foo
9+
inline def fooCallerM: Unit = ${ fooMacro }
10+
def fooMacro(using Quotes): Expr[Unit] =
11+
'{ foo }
12+
val fooExpr = '{ foo }
13+
'{ $fooExpr }

tests/pos-macros/i13546/Test_2.scala

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import mylib.Main
2+
3+
object Test:
4+
Main.fooCaller
5+
Main.fooCallerM

0 commit comments

Comments
 (0)