diff --git a/compiler/src/dotty/tools/dotc/CompilationUnit.scala b/compiler/src/dotty/tools/dotc/CompilationUnit.scala index 4ea9b558ea7f..0889550a4d74 100644 --- a/compiler/src/dotty/tools/dotc/CompilationUnit.scala +++ b/compiler/src/dotty/tools/dotc/CompilationUnit.scala @@ -97,15 +97,12 @@ class CompilationUnit protected (val source: SourceFile, val info: CompilationUn // when this unit is unsuspended. depRecorder.clear() if !suspended then - if ctx.settings.YnoSuspendedUnits.value then - report.error(i"Compilation unit suspended $this (-Yno-suspended-units is set)") - else - if (ctx.settings.XprintSuspension.value) - report.echo(i"suspended: $this") - suspended = true - ctx.run.nn.suspendedUnits += this - if ctx.phase == Phases.inliningPhase then - suspendedAtInliningPhase = true + if ctx.settings.XprintSuspension.value then + report.echo(i"suspended: $this") + suspended = true + ctx.run.nn.suspendedUnits += this + if ctx.phase == Phases.inliningPhase then + suspendedAtInliningPhase = true throw CompilationUnit.SuspendException() private var myAssignmentSpans: Map[Int, List[Span]] | Null = null diff --git a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala index 1b4d985c7c4c..1ab58040603f 100644 --- a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala @@ -1033,7 +1033,7 @@ class Inliner(val call: tpd.Tree)(using Context): } } - private def expandMacro(body: Tree, splicePos: SrcPos)(using Context) = { + private def expandMacro(body: Tree, splicePos: SrcPos)(using Context): Tree = { assert(level == 0) val inlinedFrom = enclosingInlineds.last val dependencies = macroDependencies(body)(using spliceContext) @@ -1048,7 +1048,12 @@ class Inliner(val call: tpd.Tree)(using Context): if (suspendable && ctx.settings.XprintSuspension.value) report.echo(i"suspension triggered by macro call to ${sym.showLocated} in ${sym.associatedFile}", call.srcPos) if suspendable then - ctx.compilationUnit.suspend() // this throws a SuspendException + if ctx.settings.YnoSuspendedUnits.value then + return ref(defn.Predef_undefined) + .withType(ErrorType(em"could not expand macro, suspended units are disabled by -Yno-suspended-units")) + .withSpan(splicePos.span) + else + ctx.compilationUnit.suspend() // this throws a SuspendException val evaluatedSplice = inContext(quoted.MacroExpansion.context(inlinedFrom)) { Splicer.splice(body, splicePos, inlinedFrom.srcPos, MacroClassLoader.fromContext) diff --git a/compiler/src/dotty/tools/dotc/quoted/Interpreter.scala b/compiler/src/dotty/tools/dotc/quoted/Interpreter.scala index 17e23ebcf014..2acc82c90594 100644 --- a/compiler/src/dotty/tools/dotc/quoted/Interpreter.scala +++ b/compiler/src/dotty/tools/dotc/quoted/Interpreter.scala @@ -368,6 +368,9 @@ object Interpreter: } def suspendOnMissing(sym: Symbol, pos: SrcPos)(using Context): Nothing = - if ctx.settings.XprintSuspension.value then - report.echo(i"suspension triggered by a dependency on $sym", pos) - ctx.compilationUnit.suspend() // this throws a SuspendException + if ctx.settings.YnoSuspendedUnits.value then + throw StopInterpretation(em"suspension triggered by a dependency on missing $sym not allowed with -Yno-suspended-units", pos) + else + if ctx.settings.XprintSuspension.value then + report.echo(i"suspension triggered by a dependency on missing $sym", pos) + ctx.compilationUnit.suspend() // this throws a SuspendException