Skip to content

Commit e363d56

Browse files
committed
Fix #7343: Detect inlined quotes
1 parent a0690e1 commit e363d56

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,16 +1136,22 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
11361136
}
11371137

11381138
override def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context): Tree =
1139-
tryInline(tree.asInstanceOf[tpd.Tree]) `orElse` super.typedIdent(tree, pt)
1139+
checkStaging(tryInline(tree.asInstanceOf[tpd.Tree]) `orElse` super.typedIdent(tree, pt))
11401140

11411141
override def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = {
11421142
assert(tree.hasType, tree)
11431143
val qual1 = typed(tree.qualifier, selectionProto(tree.name, pt, this))
11441144
val res = constToLiteral(untpd.cpy.Select(tree)(qual1, tree.name).withType(tree.typeOpt))
11451145
ensureAccessible(res.tpe, tree.qualifier.isInstanceOf[untpd.Super], tree.sourcePos)
1146-
res
1146+
checkStaging(res)
11471147
}
11481148

1149+
private def checkStaging(tree: Tree): tree.type =
1150+
val sym = tree.symbol
1151+
if sym == defn.InternalQuoted_exprQuote || sym == defn.InternalQuoted_typeQuote then
1152+
ctx.compilationUnit.needsStaging = true
1153+
tree
1154+
11491155
override def typedIf(tree: untpd.If, pt: Type)(implicit ctx: Context): Tree =
11501156
typed(tree.cond, defn.BooleanType) match {
11511157
case cond1 @ ConstantValue(b: Boolean) =>

tests/pos-macros/i7343/Macro_1.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.quoted.{ QuoteContext, Expr }
2+
3+
trait M {
4+
def f: Any
5+
}
6+
7+
inline def g(em: Expr[M])(using QuoteContext) = '{$em.f}

tests/pos-macros/i7343/Test_2.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import scala.quoted.{ QuoteContext, Expr }
2+
3+
def h(m: Expr[M])(using QuoteContext): Expr[Any] = g(m)

tests/pos-macros/i7343b/Macro_1.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
inline def g(using scala.quoted.QuoteContext) = '{1}

tests/pos-macros/i7343b/Test_2.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def h(using scala.quoted.QuoteContext) = g

0 commit comments

Comments
 (0)