Skip to content

Commit ae68ec7

Browse files
committed
Fix #9227: Do not suspend REPL compilation unit
1 parent a938fc8 commit ae68ec7

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import typer.Nullables
1414
import transform.SymUtils._
1515
import core.Decorators.{given _}
1616
import config.SourceVersion
17+
import StdNames.str
1718

1819
class CompilationUnit protected (val source: SourceFile) {
1920

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

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

29+
def isREPL: Boolean = source.file.name.startsWith(str.REPL_SESSION_LINE)
30+
2831
/** The source version for this unit, as determined by a language import */
2932
var sourceVersion: Option[SourceVersion] = None
3033

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,14 +1407,15 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
14071407
assert(level == 0)
14081408
val inlinedFrom = enclosingInlineds.last
14091409
val dependencies = macroDependencies(body)
1410-
1410+
val inREPL = ctx.compilationUnit.isREPL
14111411
if dependencies.nonEmpty && !ctx.reporter.errorsReported then
14121412
for sym <- dependencies do
14131413
if ctx.compilationUnit.source.file == sym.associatedFile then
14141414
ctx.error(em"Cannot call macro $sym defined in the same source file", call.sourcePos)
1415-
if (ctx.settings.XprintSuspension.value)
1415+
if (ctx.settings.XprintSuspension.value && !inREPL)
14161416
ctx.echo(i"suspension triggered by macro call to ${sym.showLocated} in ${sym.associatedFile}", call.sourcePos)
1417-
ctx.compilationUnit.suspend() // this throws a SuspendException
1417+
if !inREPL then
1418+
ctx.compilationUnit.suspend() // this throws a SuspendException
14181419

14191420
val evaluatedSplice = inContext(tastyreflect.MacroExpansion.context(inlinedFrom)) {
14201421
Splicer.splice(body, inlinedFrom.sourcePos, MacroClassLoader.fromContext)

compiler/test-resources/repl/i9227

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
scala> import scala.quoted._; inline def myMacro[T]: Unit = ${ myMacroImpl[T] }; def myMacroImpl[T](using qctx: QuoteContext): Expr[Unit] = '{}; println(myMacro[Int])
2+
1 | import scala.quoted._; inline def myMacro[T]: Unit = ${ myMacroImpl[T] }; def myMacroImpl[T](using qctx: QuoteContext): Expr[Unit] = '{}; println(myMacro[Int])
3+
| ^^^^^^^^^^^^
4+
| Cannot call macro method myMacroImpl defined in the same source file
5+
| This location contains code that was inlined from rs$line$1:1

0 commit comments

Comments
 (0)