Skip to content

Commit 3972a02

Browse files
Backport "Make sure that the stacktrace is shown with -Ydebug-unpickling" to LTS (#20801)
Backports #19115 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents b4484f1 + 9c081ca commit 3972a02

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

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

+16-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ abstract class TypeError(using creationContext: Context) extends Exception(""):
2222
* This is expensive and only useful for debugging purposes.
2323
*/
2424
def computeStackTrace: Boolean =
25-
ctx.debug || (cyclicErrors != noPrinter && this.isInstanceOf[CyclicReference] && !(ctx.mode is Mode.CheckCyclic))
25+
ctx.debug
26+
|| (cyclicErrors != noPrinter && this.isInstanceOf[CyclicReference] && !(ctx.mode is Mode.CheckCyclic))
27+
|| ctx.settings.YdebugTypeError.value
28+
|| ctx.settings.YdebugError.value
29+
|| ctx.settings.YdebugUnpickling.value
2630

2731
override def fillInStackTrace(): Throwable =
2832
if computeStackTrace then super.fillInStackTrace().nn
@@ -188,3 +192,14 @@ object CyclicReference:
188192
ex
189193
end CyclicReference
190194

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
@@ -128,12 +128,7 @@ class TreeUnpickler(reader: TastyReader,
128128
def where =
129129
val f = denot.symbol.associatedFile
130130
if f == null then "" else s" in $f"
131-
if ctx.settings.YdebugUnpickling.value then throw ex
132-
else throw TypeError(
133-
em"""Could not read definition of $denot$where
134-
|An exception was encountered:
135-
| $ex
136-
|Run with -Ydebug-unpickling to see full stack trace.""")
131+
throw UnpicklingError(denot, where, ex)
137132
treeAtAddr(currentAddr) =
138133
try
139134
atPhaseBeforeTransforms {

0 commit comments

Comments
 (0)