Skip to content

Commit

Permalink
Backport "Make sure that the stacktrace is shown with `-Ydebug-unpick…
Browse files Browse the repository at this point in the history
…ling`" to LTS (#20801)

Backports #19115 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jun 26, 2024
2 parents b4484f1 + 9c081ca commit 3972a02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
17 changes: 16 additions & 1 deletion compiler/src/dotty/tools/dotc/core/TypeErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ abstract class TypeError(using creationContext: Context) extends Exception(""):
* This is expensive and only useful for debugging purposes.
*/
def computeStackTrace: Boolean =
ctx.debug || (cyclicErrors != noPrinter && this.isInstanceOf[CyclicReference] && !(ctx.mode is Mode.CheckCyclic))
ctx.debug
|| (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 @@ -188,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 @@ -128,12 +128,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

0 comments on commit 3972a02

Please sign in to comment.