Skip to content

Commit 994dc98

Browse files
jchybWojciechMazur
authored andcommitted
Set inlining phase in context used for checking macro trees
[Cherry-picked 9f5618b]
1 parent b9f3fe3 commit 994dc98

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,9 +775,19 @@ object TreeChecker {
775775

776776
def checkMacroGeneratedTree(original: tpd.Tree, expansion: tpd.Tree)(using Context): Unit =
777777
if ctx.settings.XcheckMacros.value then
778+
// We want make sure that transparent inline macros are checked in the same way that
779+
// non transparent macros are, so we try to prepare a context which would make
780+
// the checks behave the same way for both types of macros.
781+
//
782+
// E.g. Different instances of skolem types are by definition not able to be a subtype of
783+
// one another, however in practice this is only upheld during typer phase, and we do not want
784+
// it to be upheld during this check.
785+
// See issue: #17009
778786
val checkingCtx = ctx
779787
.fresh
780788
.setReporter(new ThrowingReporter(ctx.reporter))
789+
.setPhase(ctx.base.inliningPhase)
790+
781791
val phases = ctx.base.allPhases.toList
782792
val treeChecker = new LocalChecker(previousPhases(phases))
783793

tests/pos-macros/i17009/Macro_1.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.quoted._
2+
3+
object Macro {
4+
transparent inline def transform[T](inline expr: T): T = ${ transformImpl[T]('expr) }
5+
def transformImpl[T: Type](f: Expr[T])(using Quotes): Expr[T] = f
6+
}

tests/pos-macros/i17009/Main_2.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def processLine(line: String): Unit = {
2+
Macro.transform {
3+
line.split(" ").nn
4+
???
5+
}
6+
}

0 commit comments

Comments
 (0)