diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 0bace6d2e75b..8b163acb1fa9 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -261,6 +261,7 @@ private sealed trait YSettings: val YdebugTreeWithId: Setting[Int] = IntSetting("-Ydebug-tree-with-id", "Print the stack trace when the tree with the given id is created.", Int.MinValue) val YdebugTypeError: Setting[Boolean] = BooleanSetting("-Ydebug-type-error", "Print the stack trace when a TypeError is caught", false) val YdebugError: Setting[Boolean] = BooleanSetting("-Ydebug-error", "Print the stack trace when any error is caught.", false) + val YdebugUnpickling: Setting[Boolean] = BooleanSetting("-Ydebug-unpickling", "Print the stack trace when an error occurs when reading Tasty.", false) val YtermConflict: Setting[String] = ChoiceSetting("-Yresolve-term-conflict", "strategy", "Resolve term conflicts", List("package", "object", "error"), "error") val Ylog: Setting[List[String]] = PhasesSetting("-Ylog", "Log operations during") val YlogClasspath: Setting[Boolean] = BooleanSetting("-Ylog-classpath", "Output information about what classpath is being applied.") diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 06dc4872c7f3..aea6a4140e5a 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -115,10 +115,25 @@ class TreeUnpickler(reader: TastyReader, val owner = ctx.owner val source = ctx.source def complete(denot: SymDenotation)(using Context): Unit = - treeAtAddr(currentAddr) = atPhaseBeforeTransforms { - new TreeReader(reader).readIndexedDef()( - using ctx.withOwner(owner).withSource(source)) - } + def fail(ex: Throwable) = + 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.""") + treeAtAddr(currentAddr) = + try + atPhaseBeforeTransforms { + new TreeReader(reader).readIndexedDef()( + using ctx.withOwner(owner).withSource(source)) + } + catch + case ex: AssertionError => fail(ex) + case ex: Exception => fail(ex) } class TreeReader(val reader: TastyReader) { diff --git a/tests/neg/i12482.check b/tests/neg/i12482.check new file mode 100644 index 000000000000..1ec31af86121 --- /dev/null +++ b/tests/neg/i12482.check @@ -0,0 +1,6 @@ +-- [E006] Not Found Error: tests/neg/i12482.scala:3:2 ------------------------------------------------------------------ +3 | FileZipArchive // error + | ^^^^^^^^^^^^^^ + | Not found: FileZipArchive + | + | longer explanation available when compiling with `-explain` diff --git a/tests/neg/i12482.scala b/tests/neg/i12482.scala new file mode 100644 index 000000000000..44a3b7afd97e --- /dev/null +++ b/tests/neg/i12482.scala @@ -0,0 +1,4 @@ +package dotty.tools.io +object ZipArchive { + FileZipArchive // error +} \ No newline at end of file