summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2009-12-17 11:03:57 +0000
committerMartin Odersky <odersky@gmail.com>2009-12-17 11:03:57 +0000
commit65bd378795d655679778ce2699f2a3c4f0580235 (patch)
treedae755582397dc1aa37b8bcb1f55737f8f499d5b /src/compiler
parent1a7200a1d20afb60bf5e1eb912e7e31c3156a851 (diff)
downloadscala-65bd378795d655679778ce2699f2a3c4f0580235.tar.gz
scala-65bd378795d655679778ce2699f2a3c4f0580235.tar.bz2
scala-65bd378795d655679778ce2699f2a3c4f0580235.zip
hardening the compiler to avoid exceptions I ob...
hardening the compiler to avoid exceptions I observed when used under Eclipse.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Types.scala15
-rw-r--r--src/compiler/scala/tools/nsc/transform/OverridingPairs.scala39
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala3
3 files changed, 43 insertions, 14 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala
index 18597a037c..24abef8944 100644
--- a/src/compiler/scala/tools/nsc/symtab/Types.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Types.scala
@@ -118,16 +118,23 @@ trait Types {
// `block` should not affect constraints on typevars
def undo[T](block: => T): T = {
val before = log
- val result = block
- undoTo(before)
+ val result = try {
+ block
+ } finally {
+ undoTo(before)
+ }
result
}
// if `block` evaluates to false, it should not affect constraints on typevars
def undoUnless(block: => Boolean): Boolean = {
val before = log
- val result = block
- if(!result) undoTo(before)
+ var result = false
+ try {
+ result = block
+ } finally {
+ if(!result) undoTo(before)
+ }
result
}
}
diff --git a/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala b/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala
index 9ccc4a8320..cdbea6fcfe 100644
--- a/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala
+++ b/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala
@@ -104,6 +104,10 @@ abstract class OverridingPairs {
*/
private val index = new HashMap[Symbol, Int]
+ // Note: overridingPairs can be called at odd instances by the Eclipse plugin
+ // Soemtimes symbols are not yet defined and we get missing keys.
+ // The implementation here is hardened so that it does not crash on a missing key.
+
{ var i = 0
for (bc <- base.info.baseClasses) {
index(bc) = i
@@ -126,22 +130,37 @@ abstract class OverridingPairs {
{ for (i <- List.range(0, size))
subParents(i) = new BitSet(size);
for (p <- parents) {
- val pIndex = index(p.typeSymbol)
- for (bc <- p.baseClasses)
- if (p.baseType(bc) =:= self.baseType(bc))
- include(subParents(index(bc)), pIndex)
- else if (settings.debug.value)
- log("SKIPPING "+p+" -> "+p.baseType(bc)+" / "+self.baseType(bc)+" from "+base)
+ index get p.typeSymbol match {
+ case Some(pIndex) =>
+ for (bc <- p.baseClasses)
+ if (p.baseType(bc) =:= self.baseType(bc))
+ index get bc match {
+ case Some(bcIndex) =>
+ include(subParents(bcIndex), pIndex)
+ case None =>
+ }
+ else if (settings.debug.value)
+ log("SKIPPING "+p+" -> "+p.baseType(bc)+" / "+self.baseType(bc)+" from "+base)
+ case None =>
+ }
}
- }
+ }
/** Do `sym1` and `sym2` have a common subclass in `parents`?
* In that case we do not follow their overriding pairs
*/
private def hasCommonParentAsSubclass(sym1: Symbol, sym2: Symbol) = {
- val index1 = index(sym1.owner)
- val index2 = index(sym2.owner)
- intersectionContainsElementLeq(subParents(index1), subParents(index2), index1 min index2)
+ index get sym1.owner match {
+ case Some(index1) =>
+ index get sym2.owner match {
+ case Some(index2) =>
+ intersectionContainsElementLeq(subParents(index1), subParents(index2), index1 min index2)
+ case None =>
+ false
+ }
+ case None =>
+ false
+ }
}
/** The scope entries that have already been visited as overridden
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 1c746d0ab9..e541c58c1a 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -4026,6 +4026,9 @@ trait Typers { self: Analyzer =>
// and we try again (@see tryTypedApply). In that case we can assign
// whatever type to tree; we just have to survive until a real error message is issued.
tree setType AnyClass.tpe
+ case Import(expr, selectors) =>
+ assert(onlyPresentation) // should not happen in normal circumstances.
+ tree setType tree.symbol.tpe
case _ =>
throw new Error("unexpected tree: " + tree.getClass + "\n" + tree)//debug
}