Skip to content

Commit

Permalink
Merge pull request #14884 from dotty-staging/fix-12482
Browse files Browse the repository at this point in the history
Survive unpickling crashes when completing from Tasty
  • Loading branch information
nicolasstucki authored Apr 11, 2022
2 parents 3430154 + 8374d35 commit e35b6ff
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
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
}

0 comments on commit e35b6ff

Please sign in to comment.