Skip to content

Commit 90f9d22

Browse files
committed
Make sure that the stacktrace is shown with -Ydebug-unpickling
1 parent 4d45087 commit 90f9d22

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

compiler/src/dotty/tools/dotc/core/TypeErrors.scala

+12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ abstract class TypeError(using creationContext: Context) extends Exception(""):
2626
|| (cyclicErrors != noPrinter && this.isInstanceOf[CyclicReference] && !(ctx.mode is Mode.CheckCyclic))
2727
|| ctx.settings.YdebugTypeError.value
2828
|| ctx.settings.YdebugError.value
29+
|| ctx.settings.YdebugUnpickling.value
2930

3031
override def fillInStackTrace(): Throwable =
3132
if computeStackTrace then super.fillInStackTrace().nn
@@ -191,3 +192,14 @@ object CyclicReference:
191192
ex
192193
end CyclicReference
193194

195+
class UnpicklingError(denot: Denotation, where: String, cause: Throwable)(using Context) extends TypeError:
196+
override def toMessage(using Context): Message =
197+
val debugUnpickling = cause match
198+
case cause: UnpicklingError => ""
199+
case _ =>
200+
if ctx.settings.YdebugUnpickling.value then
201+
cause.getStackTrace().nn.mkString("\n ", "\n ", "")
202+
else "\n\nRun with -Ydebug-unpickling to see full stack trace."
203+
em"""Could not read definition $denot$where. Caused by the following exception:
204+
|$cause$debugUnpickling"""
205+
end UnpicklingError

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

+1-6
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,7 @@ class TreeUnpickler(reader: TastyReader,
145145
def where =
146146
val f = denot.symbol.associatedFile
147147
if f == null then "" else s" in $f"
148-
if ctx.settings.YdebugUnpickling.value then throw ex
149-
else throw TypeError(
150-
em"""Could not read definition of $denot$where
151-
|An exception was encountered:
152-
| $ex
153-
|Run with -Ydebug-unpickling to see full stack trace.""")
148+
throw UnpicklingError(denot, where, ex)
154149
treeAtAddr(currentAddr) =
155150
try
156151
atPhaseBeforeTransforms {

0 commit comments

Comments
 (0)