Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure that the stacktrace is shown with -Ydebug-unpickling #19115

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TypeErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
7 changes: 1 addition & 6 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading