Skip to content

Commit ce5d909

Browse files
committed
Made LazyType fail more graciously with incompl...
Made LazyType fail more graciously with incomplete class paths. SymbolLoaders already do the right thing, printing an error instead of crashing the compiler. However, the unpickler has two more lazy types that crash and stop the compiler if, on completion, it encounters a reference to a missing class file. Since the SymbolTable has no way of reporting an error, we convert the MissingRequirementError in TypeErrors. This has the benefit of being printed nicely by the type checker (with a position where the type was needed). This fixes extremely worrying behavior in the IDE when the class path is incomplete (for instance, after a rebuild with compilation errors). review by odersky, extempore.
1 parent 3ba3b39 commit ce5d909

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/compiler/scala/reflect/internal/pickling/UnPickler.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,15 +834,20 @@ abstract class UnPickler /*extends reflect.generic.UnPickler*/ {
834834
def newLazyTypeRef(i: Int): LazyType = new LazyTypeRef(i)
835835
def newLazyTypeRefAndAlias(i: Int, j: Int): LazyType = new LazyTypeRefAndAlias(i, j)
836836

837+
def toTypeError(e: MissingRequirementError) =
838+
new TypeError(e.msg)
839+
837840
/** A lazy type which when completed returns type at index `i`. */
838841
private class LazyTypeRef(i: Int) extends LazyType {
839842
private val definedAtRunId = currentRunId
840843
private val p = phase
841-
override def complete(sym: Symbol) : Unit = {
844+
override def complete(sym: Symbol) : Unit = try {
842845
val tp = at(i, () => readType(sym.isTerm)) // after NMT_TRANSITION, revert `() => readType(sym.isTerm)` to `readType`
843846
if (p != phase) atPhase(p) (sym setInfo tp)
844847
else sym setInfo tp
845848
if (currentRunId != definedAtRunId) sym.setInfo(adaptToNewRunMap(tp))
849+
} catch {
850+
case e: MissingRequirementError => throw toTypeError(e)
846851
}
847852
override def load(sym: Symbol) { complete(sym) }
848853
}
@@ -851,7 +856,7 @@ abstract class UnPickler /*extends reflect.generic.UnPickler*/ {
851856
* of completed symbol to symbol at index `j`.
852857
*/
853858
private class LazyTypeRefAndAlias(i: Int, j: Int) extends LazyTypeRef(i) {
854-
override def complete(sym: Symbol) {
859+
override def complete(sym: Symbol) = try {
855860
super.complete(sym)
856861
var alias = at(j, readSymbol)
857862
if (alias.isOverloaded) {
@@ -860,6 +865,8 @@ abstract class UnPickler /*extends reflect.generic.UnPickler*/ {
860865
}
861866
}
862867
sym.asInstanceOf[TermSymbol].setAlias(alias)
868+
} catch {
869+
case e: MissingRequirementError => throw toTypeError(e)
863870
}
864871
}
865872
}

0 commit comments

Comments
 (0)