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

Survive unpickling crashes when completing from Tasty #14884

Merged
merged 1 commit into from
Apr 11, 2022
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
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
23 changes: 19 additions & 4 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions tests/neg/i12482.check
Original file line number Diff line number Diff line change
@@ -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`
4 changes: 4 additions & 0 deletions tests/neg/i12482.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package dotty.tools.io
object ZipArchive {
FileZipArchive // error
}