From 90f9d224379ed4fe863a76e805485c1d5cb8bfce Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 1 Dec 2023 09:03:02 +0100 Subject: [PATCH] Make sure that the stacktrace is shown with `-Ydebug-unpickling` --- compiler/src/dotty/tools/dotc/core/TypeErrors.scala | 12 ++++++++++++ .../dotty/tools/dotc/core/tasty/TreeUnpickler.scala | 7 +------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeErrors.scala b/compiler/src/dotty/tools/dotc/core/TypeErrors.scala index 2fa769e25852..76be98d9bd65 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErrors.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErrors.scala @@ -26,6 +26,7 @@ abstract class TypeError(using creationContext: Context) extends Exception(""): || (cyclicErrors != noPrinter && this.isInstanceOf[CyclicReference] && !(ctx.mode is Mode.CheckCyclic)) || ctx.settings.YdebugTypeError.value || ctx.settings.YdebugError.value + || ctx.settings.YdebugUnpickling.value override def fillInStackTrace(): Throwable = if computeStackTrace then super.fillInStackTrace().nn @@ -191,3 +192,14 @@ object CyclicReference: ex end CyclicReference +class UnpicklingError(denot: Denotation, where: String, cause: Throwable)(using Context) extends TypeError: + override def toMessage(using Context): Message = + val debugUnpickling = cause match + case cause: UnpicklingError => "" + case _ => + if ctx.settings.YdebugUnpickling.value then + cause.getStackTrace().nn.mkString("\n ", "\n ", "") + else "\n\nRun with -Ydebug-unpickling to see full stack trace." + em"""Could not read definition $denot$where. Caused by the following exception: + |$cause$debugUnpickling""" +end UnpicklingError diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index d4271d5bffaf..36db98523f34 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -145,12 +145,7 @@ class TreeUnpickler(reader: TastyReader, def where = val f = denot.symbol.associatedFile if f == null then "" else s" in $f" - if ctx.settings.YdebugUnpickling.value then throw ex - else throw TypeError( - em"""Could not read definition of $denot$where - |An exception was encountered: - | $ex - |Run with -Ydebug-unpickling to see full stack trace.""") + throw UnpicklingError(denot, where, ex) treeAtAddr(currentAddr) = try atPhaseBeforeTransforms {