Skip to content

Commit 0d4dbaa

Browse files
committed
Fix scala#7343: Detect inlined quotes
1 parent 8a42819 commit 0d4dbaa

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
@@ -1098,16 +1098,22 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
10981098
}
10991099

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

11031103
override def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = {
11041104
assert(tree.hasType, tree)
11051105
val qual1 = typed(tree.qualifier, selectionProto(tree.name, pt, this))
11061106
val res = constToLiteral(untpd.cpy.Select(tree)(qual1, tree.name).withType(tree.typeOpt))
11071107
ensureAccessible(res.tpe, tree.qualifier.isInstanceOf[untpd.Super], tree.sourcePos)
1108-
res
1108+
checkStaging(res)
11091109
}
11101110

1111+
private def checkStaging(tree: Tree): tree.type =
1112+
val sym = tree.symbol
1113+
if sym == defn.InternalQuoted_exprQuote || sym == defn.InternalQuoted_typeQuote then
1114+
ctx.compilationUnit.needsStaging = true
1115+
tree
1116+
11111117
override def typedIf(tree: untpd.If, pt: Type)(implicit ctx: Context): Tree =
11121118
typed(tree.cond, defn.BooleanType) match {
11131119
case cond1 @ ConstantValue(b: Boolean) =>

tests/run-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/run-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/run-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/run-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)