Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/CompilationUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import typer.Nullables
import transform.SymUtils._
import core.Decorators.{given _}
import config.SourceVersion
import StdNames.str

class CompilationUnit protected (val source: SourceFile) {

Expand All @@ -25,6 +26,8 @@ class CompilationUnit protected (val source: SourceFile) {

def isJava: Boolean = source.file.name.endsWith(".java")

def isREPL: Boolean = source.file.name.startsWith(str.REPL_SESSION_LINE)

/** The source version for this unit, as determined by a language import */
var sourceVersion: Option[SourceVersion] = None

Expand Down
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1407,14 +1407,15 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
assert(level == 0)
val inlinedFrom = enclosingInlineds.last
val dependencies = macroDependencies(body)

val inREPL = ctx.compilationUnit.isREPL
if dependencies.nonEmpty && !ctx.reporter.errorsReported then
for sym <- dependencies do
if ctx.compilationUnit.source.file == sym.associatedFile then
ctx.error(em"Cannot call macro $sym defined in the same source file", call.sourcePos)
if (ctx.settings.XprintSuspension.value)
if (ctx.settings.XprintSuspension.value && !inREPL)
ctx.echo(i"suspension triggered by macro call to ${sym.showLocated} in ${sym.associatedFile}", call.sourcePos)
ctx.compilationUnit.suspend() // this throws a SuspendException
if !inREPL then
ctx.compilationUnit.suspend() // this throws a SuspendException

val evaluatedSplice = inContext(tastyreflect.MacroExpansion.context(inlinedFrom)) {
Splicer.splice(body, inlinedFrom.sourcePos, MacroClassLoader.fromContext)
Expand Down
5 changes: 5 additions & 0 deletions compiler/test-resources/repl/i9227
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
scala> import scala.quoted._; inline def myMacro[T]: Unit = ${ myMacroImpl[T] }; def myMacroImpl[T](using qctx: QuoteContext): Expr[Unit] = '{}; println(myMacro[Int])
1 | import scala.quoted._; inline def myMacro[T]: Unit = ${ myMacroImpl[T] }; def myMacroImpl[T](using qctx: QuoteContext): Expr[Unit] = '{}; println(myMacro[Int])
| ^^^^^^^^^^^^
| Cannot call macro method myMacroImpl defined in the same source file
| This location contains code that was inlined from rs$line$1:1