Skip to content

Commit 787baa4

Browse files
committed
Harden ImportSuggestions
I got an error: ``` error while loading Enum$, class file /Users/odersky/workspace/dotty/library/target/scala-0.27/classes/scala/Enum.class is broken, reading aborted with class dotty.tools.tasty.UnpickleException TASTy signature has wrong version. expected: 24.0 found : 23.0 ``` even though there was no enum in my program. It turned out that the error was generated when ImportSuggestions tried to access an outdated class file on the class path. This shoul dnot cause an error; instead the class file should be just ignored.
1 parent ff42223 commit 787baa4

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import ast.{untpd, tpd}
1313
import Implicits.{hasExtMethod, Candidate}
1414
import java.util.{Timer, TimerTask}
1515
import collection.mutable
16+
import scala.util.control.NonFatal
1617

1718
/** This trait defines the method `importSuggestionAddendum` that adds an addendum
1819
* to error messages suggesting additional imports.
@@ -58,10 +59,12 @@ trait ImportSuggestions:
5859
val seen = mutable.Set[TermRef]()
5960

6061
def lookInside(root: Symbol)(using Context): Boolean =
61-
if root.is(Package) then root.isTerm && root.isCompleted
62-
else !root.name.is(FlatName)
63-
&& !root.name.lastPart.contains('$')
64-
&& root.is(ModuleVal, butNot = JavaDefined)
62+
explore {
63+
if root.is(Package) then root.isTerm && root.isCompleted
64+
else !root.name.is(FlatName)
65+
&& !root.name.lastPart.contains('$')
66+
&& root.is(ModuleVal, butNot = JavaDefined)
67+
}
6568

6669
def nestedRoots(site: Type)(using Context): List[Symbol] =
6770
val seenNames = mutable.Set[Name]()
@@ -245,12 +248,11 @@ trait ImportSuggestions:
245248
match
246249
case (Nil, partials) => (extensionImports, partials)
247250
case givenImports => givenImports
248-
catch
249-
case ex: Throwable =>
250-
if ctx.settings.Ydebug.value then
251-
println("caught exception when searching for suggestions")
252-
ex.printStackTrace()
253-
(Nil, Nil)
251+
catch case NonFatal(ex) =>
252+
if ctx.settings.Ydebug.value then
253+
println("caught exception when searching for suggestions")
254+
ex.printStackTrace()
255+
(Nil, Nil)
254256
finally
255257
timer.cancel()
256258
reduceTimeBudget(((System.currentTimeMillis() - start) min Int.MaxValue).toInt)

0 commit comments

Comments
 (0)