Skip to content

Commit 59f7e65

Browse files
Merge pull request #8642 from dotty-staging/fix-#7343
Fix #7343: Detect inlined quotes
2 parents 060a3ec + e3454bd commit 59f7e65

File tree

10 files changed

+31
-10
lines changed

10 files changed

+31
-10
lines changed

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

+1-8
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,7 @@ class ReifyQuotes extends MacroTransform {
282282

283283
val tpe = MethodType(defn.SeqType.appliedTo(defn.AnyType) :: Nil, tree.tpe.widen)
284284
val meth = ctx.newSymbol(lambdaOwner, UniqueName.fresh(nme.ANON_FUN), Synthetic | Method, tpe)
285-
val closure = Closure(meth, tss => body(tss.head.head)(ctx.withOwner(meth)).changeOwner(ctx.owner, meth)).withSpan(tree.span)
286-
287-
enclosingInlineds match {
288-
case enclosingInline :: _ =>
289-
// In case a tree was inlined inside of the quote and we this closure corresponds to code within it we need to keep the inlined node.
290-
Inlined(enclosingInline, Nil, closure)(ctx.withSource(lambdaOwner.topLevelClass.source))
291-
case Nil => closure
292-
}
285+
Closure(meth, tss => body(tss.head.head)(ctx.withOwner(meth)).changeOwner(ctx.owner, meth)).withSpan(tree.span)
293286
}
294287

295288
private def transformWithCapturer(tree: Tree)(capturer: mutable.Map[Symbol, Tree] => Tree => Tree)(implicit ctx: Context): Tree = {

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

+8-2
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/i7322/Macro_1.scala

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

tests/pos-macros/i7322/Test_2.scala

+3
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[String]])(using QuoteContext): Expr[Any] = g(m)

tests/pos-macros/i7343/Macro_1.scala

+7
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

+3
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

+1
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

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def h(using scala.quoted.QuoteContext) = g

0 commit comments

Comments
 (0)