Skip to content

Commit fe55cef

Browse files
authored
Make sure that the stacktrace is shown with -Ydebug-unpickling (#19115)
#### New behaviour, tested on #18967 ```scala // Test.scala def test: Option[Int] = ??? ``` ``` sbt> set ThisBuild/Build.scala2Library := Build.Scala2LibraryCCTasty sbt> scala3-bootstrapped/scalac Test.scala -- Error: Test.scala:1:10 ---------------------------------------------------- 1 |def test: Option[Int] = ??? | ^ |Could not read definition class Option in out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/Option.tasty). Caused by the following exception: |dotty.tools.dotc.core.UnpicklingError: Could not read definition type IterableOnce in out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/package.tasty). Caused by the following exception: |dotty.tools.dotc.core.UnpicklingError: Could not read definition trait IterableOnce in out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/collection/IterableOnce.tasty). Caused by the following exception: |dotty.tools.dotc.core.UnpicklingError: Could not read definition trait Iterable in out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/collection/immutable/Iterable.tasty). Caused by the following exception: |dotty.tools.dotc.core.UnpicklingError: Could not read definition trait Iterable out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/collection/Iterable.tasty). Caused by the following exception: |dotty.tools.dotc.core.CyclicReference: Cyclic reference involving trait Seq | |Run with -Ydebug-unpickling to see full stack trace. sbt> scala3-bootstrapped/scalac -Ydebug-unpickling Test.scala -- Error: Test.scala:1:10 ---------------------------------------------------- 1 |def test: Option[Int] = ??? | ^ |Could not read definition class Option in out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/Option.tasty). Caused by the following exception: |dotty.tools.dotc.core.UnpicklingError: Could not read definition type IterableOnce in out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/package.tasty). Caused by the following exception: |dotty.tools.dotc.core.UnpicklingError: Could not read definition trait IterableOnce in out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/collection/IterableOnce.tasty). Caused by the following exception: |dotty.tools.dotc.core.UnpicklingError: Could not read definition trait Iterable in out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/collection/immutable/Iterable.tasty). Caused by the following exception: |dotty.tools.dotc.core.UnpicklingError: Could not read definition trait Iterable in out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/collection/Iterable.tasty). Caused by the following exception: |dotty.tools.dotc.core.CyclicReference: Cyclic reference involving trait Seq | dotty.tools.dotc.core.CyclicReference$.apply(TypeErrors.scala:186) | dotty.tools.dotc.core.SymDenotations$BaseDataImpl.apply(SymDenotations.scala:2973) | dotty.tools.dotc.core.SymDenotations$ClassDenotation.baseData(SymDenotations.scala:1954) | dotty.tools.dotc.core.SymDenotations$ClassDenotation.baseClassSet(SymDenotations.scala:1970) | dotty.tools.dotc.core.SymDenotations$ClassDenotation.isValueClass(SymDenotations.scala:2032) | dotty.tools.dotc.core.SymUtils.isDerivedValueClass(SymUtils.scala:85) | dotty.tools.dotc.core.TypeErasure$.dotty$tools$dotc$core$TypeErasure$$$erasureDependsOnArgs(TypeErasure.scala:74) | ... ``` #### Old behaviour ``` sbt> set ThisBuild/Build.scala2Library := Build.Scala2LibraryCCTasty sbt> scala3-bootstrapped/scalac Test.scala -- Error: Test.scala:1:10 ---------------------------------------------------- 1 |def test: Option[Int] = ??? | ^ |Could not read definition of class Option in /Users/nicolasstucki/Github/dotty/scala2-library-cc-tasty/../out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/Option.tasty) |An exception was encountered: | dotty.tools.dotc.core.TypeError$$anon$1: Could not read definition of type IterableOnce in /Users/nicolasstucki/Github/dotty/scala2-library-cc-tasty/../out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/package.tasty) |An exception was encountered: | dotty.tools.dotc.core.TypeError$$anon$1: Could not read definition of trait IterableOnce in /Users/nicolasstucki/Github/dotty/scala2-library-cc-tasty/../out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/collection/IterableOnce.tasty) |An exception was encountered: | dotty.tools.dotc.core.TypeError$$anon$1: Could not read definition of trait Iterable in /Users/nicolasstucki/Github/dotty/scala2-library-cc-tasty/../out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/collection/immutable/Iterable.tasty) |An exception was encountered: | dotty.tools.dotc.core.TypeError$$anon$1: Could not read definition of trait Iterable in /Users/nicolasstucki/Github/dotty/scala2-library-cc-tasty/../out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/collection/Iterable.tasty) |An exception was encountered: | dotty.tools.dotc.core.CyclicReference: Cyclic reference involving trait Seq |Run with -Ydebug-unpickling to see full stack trace. |Run with -Ydebug-unpickling to see full stack trace. |Run with -Ydebug-unpickling to see full stack trace. |Run with -Ydebug-unpickling to see full stack trace. |Run with -Ydebug-unpickling to see full stack trace. 1 error found sbt> scala3-bootstrapped/scalac t/Test.scala -Ydebug-unpickling -- Error: t/Test.scala:1:10 ---------------------------------------------------- 1 |def test: Option[Int] = ??? | ^ | Cyclic reference involving trait Seq | | longer explanation available when compiling with `-explain` 1 error found ```
2 parents 423cd6c + 90f9d22 commit fe55cef

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)