Skip to content

Commit b274cd3

Browse files
committed
Fix #7343: Detect inlined quotes
1 parent b0e7e26 commit b274cd3

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
@@ -1138,16 +1138,22 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
11381138
}
11391139

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

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

1151+
private def checkStaging(tree: Tree): tree.type =
1152+
val sym = tree.symbol
1153+
if sym == defn.InternalQuoted_exprQuote || sym == defn.InternalQuoted_typeQuote then
1154+
ctx.compilationUnit.needsStaging = true
1155+
tree
1156+
11511157
override def typedIf(tree: untpd.If, pt: Type)(using Context): Tree =
11521158
typed(tree.cond, defn.BooleanType) match {
11531159
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)