Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the inlining phase in the Context used for checking macro trees #20087

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/TreeChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,19 @@ object TreeChecker {

def checkMacroGeneratedTree(original: tpd.Tree, expansion: tpd.Tree)(using Context): Unit =
if ctx.settings.XcheckMacros.value then
// We want make sure that transparent inline macros are checked in the same way that
// non transparent macros are, so we try to prepare a context which would make
// the checks behave the same way for both types of macros.
//
// E.g. Different instances of skolem types are by definition not able to be a subtype of
// one another, however in practice this is only upheld during typer phase, and we do not want
// it to be upheld during this check.
// See issue: #17009
val checkingCtx = ctx
.fresh
.setReporter(new ThrowingReporter(ctx.reporter))
.setPhase(ctx.base.inliningPhase)

val phases = ctx.base.allPhases.toList
val treeChecker = new LocalChecker(previousPhases(phases))

Expand Down
6 changes: 6 additions & 0 deletions tests/pos-macros/i17009/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import scala.quoted._

object Macro {
transparent inline def transform[T](inline expr: T): T = ${ transformImpl[T]('expr) }
def transformImpl[T: Type](f: Expr[T])(using Quotes): Expr[T] = f
}
6 changes: 6 additions & 0 deletions tests/pos-macros/i17009/Main_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def processLine(line: String): Unit = {
Macro.transform {
line.split(" ").nn
???
}
}
Loading