From 93679006f3dfd9a156c83fcd72b6581288b07ffc Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Thu, 26 Sep 2024 16:24:24 +0200 Subject: [PATCH] Add ability to debug misfiring SuspendException It should never reach the user, but if it does because of a bug like in #18517, we should have a flag to find out where it came from. --- compiler/src/dotty/tools/dotc/CompilationUnit.scala | 2 +- compiler/src/dotty/tools/dotc/core/TypeErrors.scala | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/CompilationUnit.scala b/compiler/src/dotty/tools/dotc/CompilationUnit.scala index 0975c94e916a..01926ceaf132 100644 --- a/compiler/src/dotty/tools/dotc/CompilationUnit.scala +++ b/compiler/src/dotty/tools/dotc/CompilationUnit.scala @@ -132,7 +132,7 @@ class CompilationUnit protected (val source: SourceFile, val info: CompilationUn object CompilationUnit { - class SuspendException extends Exception with NoStackTrace + class SuspendException(using Context) extends Exception with StackTraceOnDebug /** Make a compilation unit for top class `clsd` with the contents of the `unpickled` tree */ def apply(clsd: ClassDenotation, unpickled: Tree, forceTrees: Boolean)(using Context): CompilationUnit = diff --git a/compiler/src/dotty/tools/dotc/core/TypeErrors.scala b/compiler/src/dotty/tools/dotc/core/TypeErrors.scala index 1c9696da67d1..b6cabfb3f7a9 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErrors.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErrors.scala @@ -18,8 +18,7 @@ import collection.mutable import scala.annotation.constructorOnly -abstract class TypeError(using creationContext: Context) extends Exception(""): - +trait StackTraceOnDebug(using Context) extends Throwable: /** Will the stack trace of this exception be filled in? * This is expensive and only useful for debugging purposes. */ @@ -35,6 +34,8 @@ abstract class TypeError(using creationContext: Context) extends Exception(""): if computeStackTrace then super.fillInStackTrace().nn else this +abstract class TypeError(using creationContext: Context) extends Exception("") with StackTraceOnDebug: + /** Convert to message. This takes an additional Context, so that we * use the context when the message is first produced, i.e. when the TypeError * is handled. This makes a difference for CyclicErrors since we need to know