diff options
Diffstat (limited to 'src')
6 files changed, 332 insertions, 304 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index bce9f28847..3232bde3b4 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -253,7 +253,9 @@ self => final val InBlock = 1 final val InTemplate = 2 - lazy val ScalaValueClassNames = Seq(tpnme.AnyVal, + // These symbols may not yet be loaded (e.g. in the ide) so don't go + // through definitions to obtain the names. + lazy val ScalaValueClassNames = Seq(tpnme.AnyVal, tpnme.Unit, tpnme.Boolean, tpnme.Byte, diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index daae69590f..f67cec730b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -124,7 +124,15 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT !(member.isAbstractOverride && member.isIncompleteIn(clazz))) unit.error(sel.pos, ""+sym.fullLocationString+" is accessed from super. It may not be abstract "+ "unless it is overridden by a member declared `abstract' and `override'"); + } else if (mix == tpnme.EMPTY && !sym.owner.isTrait){ + // SI-4989 Check if an intermediate class between `clazz` and `sym.owner` redeclares the method as abstract. + val intermediateClasses = clazz.info.baseClasses.tail.takeWhile(_ != sym.owner) + intermediateClasses.map(sym.overridingSymbol).find(s => s.isDeferred && !s.isAbstractOverride && !s.owner.isTrait).foreach { + absSym => + unit.error(sel.pos, s"${sym.fullLocationString} cannot be directly accessed from ${clazz} because ${absSym.owner} redeclares it as abstract") + } } + if (name.isTermName && mix == tpnme.EMPTY && (clazz.isTrait || clazz != currentClass || !validCurrentOwner)) ensureAccessor(sel) else sel diff --git a/src/library/scala/collection/immutable/IntMap.scala b/src/library/scala/collection/immutable/IntMap.scala index 039a57041c..e895c94599 100644 --- a/src/library/scala/collection/immutable/IntMap.scala +++ b/src/library/scala/collection/immutable/IntMap.scala @@ -18,17 +18,17 @@ import scala.collection.mutable.{ Builder, MapBuilder } private[immutable] object IntMapUtils extends BitOperations.Int { def branchMask(i: Int, j: Int) = highestOneBit(i ^ j) - def join[T](p1 : Int, t1 : IntMap[T], p2 : Int, t2 : IntMap[T]) : IntMap[T] = { - val m = branchMask(p1, p2); - val p = mask(p1, m); + def join[T](p1: Int, t1: IntMap[T], p2: Int, t2: IntMap[T]): IntMap[T] = { + val m = branchMask(p1, p2) + val p = mask(p1, m) if (zero(p1, m)) IntMap.Bin(p, m, t1, t2) - else IntMap.Bin(p, m, t2, t1); + else IntMap.Bin(p, m, t2, t1) } - def bin[T](prefix : Int, mask : Int, left : IntMap[T], right : IntMap[T]) : IntMap[T] = (left, right) match { - case (left, IntMap.Nil) => left; - case (IntMap.Nil, right) => right; - case (left, right) => IntMap.Bin(prefix, mask, left, right); + def bin[T](prefix: Int, mask: Int, left: IntMap[T], right: IntMap[T]): IntMap[T] = (left, right) match { + case (left, IntMap.Nil) => left + case (IntMap.Nil, right) => right + case (left, right) => IntMap.Bin(prefix, mask, left, right) } } @@ -50,9 +50,9 @@ object IntMap { } def empty[T] : IntMap[T] = IntMap.Nil; - def singleton[T](key : Int, value : T) : IntMap[T] = IntMap.Tip(key, value); - def apply[T](elems : (Int, T)*) : IntMap[T] = - elems.foldLeft(empty[T])((x, y) => x.updated(y._1, y._2)); + def singleton[T](key: Int, value: T): IntMap[T] = IntMap.Tip(key, value); + def apply[T](elems: (Int, T)*): IntMap[T] = + elems.foldLeft(empty[T])((x, y) => x.updated(y._1, y._2)) private[immutable] case object Nil extends IntMap[Nothing] { // Important! Without this equals method in place, an infinite @@ -66,15 +66,15 @@ object IntMap { } } - private[immutable] case class Tip[+T](key : Int, value : T) extends IntMap[T]{ + private[immutable] case class Tip[+T](key: Int, value: T) extends IntMap[T]{ def withValue[S](s: S) = - if (s.asInstanceOf[AnyRef] eq value.asInstanceOf[AnyRef]) this.asInstanceOf[IntMap.Tip[S]]; - else IntMap.Tip(key, s); + if (s.asInstanceOf[AnyRef] eq value.asInstanceOf[AnyRef]) this.asInstanceOf[IntMap.Tip[S]] + else IntMap.Tip(key, s) } - private[immutable] case class Bin[+T](prefix : Int, mask : Int, left : IntMap[T], right : IntMap[T]) extends IntMap[T]{ - def bin[S](left : IntMap[S], right : IntMap[S]) : IntMap[S] = { - if ((this.left eq left) && (this.right eq right)) this.asInstanceOf[IntMap.Bin[S]]; - else IntMap.Bin[S](prefix, mask, left, right); + private[immutable] case class Bin[+T](prefix: Int, mask: Int, left: IntMap[T], right: IntMap[T]) extends IntMap[T] { + def bin[S](left: IntMap[S], right: IntMap[S]): IntMap[S] = { + if ((this.left eq left) && (this.right eq right)) this.asInstanceOf[IntMap.Bin[S]] + else IntMap.Bin[S](prefix, mask, left, right) } } @@ -83,60 +83,60 @@ object IntMap { import IntMap._ // Iterator over a non-empty IntMap. -private[immutable] abstract class IntMapIterator[V, T](it : IntMap[V]) extends AbstractIterator[T] { +private[immutable] abstract class IntMapIterator[V, T](it: IntMap[V]) extends AbstractIterator[T] { // Basically this uses a simple stack to emulate conversion over the tree. However // because we know that Ints are at least 32 bits we can have at most 32 IntMap.Bins and // one IntMap.Tip sitting on the tree at any point. Therefore we know the maximum stack // depth is 33 and - var index = 0; - var buffer = new Array[AnyRef](33); + var index = 0 + var buffer = new Array[AnyRef](33) def pop = { - index -= 1; - buffer(index).asInstanceOf[IntMap[V]]; + index -= 1 + buffer(index).asInstanceOf[IntMap[V]] } - def push(x : IntMap[V]) { - buffer(index) = x.asInstanceOf[AnyRef]; - index += 1; + def push(x: IntMap[V]) { + buffer(index) = x.asInstanceOf[AnyRef] + index += 1 } - push(it); + push(it) /** * What value do we assign to a tip? */ - def valueOf(tip : IntMap.Tip[V]) : T; + def valueOf(tip: IntMap.Tip[V]): T - def hasNext = index != 0; - final def next : T = + def hasNext = index != 0 + final def next: T = pop match { case IntMap.Bin(_,_, t@IntMap.Tip(_, _), right) => { - push(right); - valueOf(t); + push(right) + valueOf(t) } case IntMap.Bin(_, _, left, right) => { - push(right); - push(left); - next; + push(right) + push(left) + next } - case t@IntMap.Tip(_, _) => valueOf(t); + case t@IntMap.Tip(_, _) => valueOf(t) // This should never happen. We don't allow IntMap.Nil in subtrees of the IntMap // and don't return an IntMapIterator for IntMap.Nil. - case IntMap.Nil => sys.error("Empty maps not allowed as subtrees"); + case IntMap.Nil => sys.error("Empty maps not allowed as subtrees") } } -private[immutable] class IntMapEntryIterator[V](it : IntMap[V]) extends IntMapIterator[V, (Int, V)](it){ - def valueOf(tip : IntMap.Tip[V]) = (tip.key, tip.value); +private[immutable] class IntMapEntryIterator[V](it: IntMap[V]) extends IntMapIterator[V, (Int, V)](it) { + def valueOf(tip: IntMap.Tip[V]) = (tip.key, tip.value) } -private[immutable] class IntMapValueIterator[V](it : IntMap[V]) extends IntMapIterator[V, V](it){ - def valueOf(tip : IntMap.Tip[V]) = tip.value +private[immutable] class IntMapValueIterator[V](it: IntMap[V]) extends IntMapIterator[V, V](it) { + def valueOf(tip: IntMap.Tip[V]) = tip.value } -private[immutable] class IntMapKeyIterator[V](it : IntMap[V]) extends IntMapIterator[V, Int](it){ - def valueOf(tip : IntMap.Tip[V]) = tip.key +private[immutable] class IntMapKeyIterator[V](it: IntMap[V]) extends IntMapIterator[V, Int](it) { + def valueOf(tip: IntMap.Tip[V]) = tip.key } import IntMap._ @@ -145,7 +145,7 @@ import IntMap._ * <a href="http://citeseer.ist.psu.edu/okasaki98fast.html">Fast Mergeable Integer Maps</a> * by Okasaki and Gill. Essentially a trie based on binary digits of the integers. * - * Note: This class is as of 2.8 largely superseded by HashMap. + * '''Note:''' This class is as of 2.8 largely superseded by HashMap. * * @tparam T type of the values associated with integer keys. * @@ -155,17 +155,16 @@ import IntMap._ * @define mayNotTerminateInf * @define willNotTerminateInf */ -sealed abstract class IntMap[+T] -extends AbstractMap[Int, T] +sealed abstract class IntMap[+T] extends AbstractMap[Int, T] with Map[Int, T] with MapLike[Int, T, IntMap[T]] { - override def empty: IntMap[T] = IntMap.Nil; + override def empty: IntMap[T] = IntMap.Nil override def toList = { - val buffer = new scala.collection.mutable.ListBuffer[(Int, T)]; - foreach(buffer += _); - buffer.toList; + val buffer = new scala.collection.mutable.ListBuffer[(Int, T)] + foreach(buffer += _) + buffer.toList } /** @@ -173,109 +172,112 @@ extends AbstractMap[Int, T] * * @return an iterator over pairs of integer keys and corresponding values. */ - def iterator : Iterator[(Int, T)] = this match { - case IntMap.Nil => Iterator.empty; - case _ => new IntMapEntryIterator(this); + def iterator: Iterator[(Int, T)] = this match { + case IntMap.Nil => Iterator.empty + case _ => new IntMapEntryIterator(this) } /** * Loops over the key, value pairs of the map in unsigned order of the keys. */ - override final def foreach[U](f : ((Int, T)) => U) : Unit = this match { - case IntMap.Bin(_, _, left, right) => {left.foreach(f); right.foreach(f); } - case IntMap.Tip(key, value) => f((key, value)); - case IntMap.Nil => {}; + override final def foreach[U](f: ((Int, T)) => U): Unit = this match { + case IntMap.Bin(_, _, left, right) => { left.foreach(f); right.foreach(f) } + case IntMap.Tip(key, value) => f((key, value)) + case IntMap.Nil => } - override def keysIterator : Iterator[Int] = this match { - case IntMap.Nil => Iterator.empty; - case _ => new IntMapKeyIterator(this); + override def keysIterator: Iterator[Int] = this match { + case IntMap.Nil => Iterator.empty + case _ => new IntMapKeyIterator(this) } /** - * Loop over the keys of the map. The same as keys.foreach(f), but may + * Loop over the keys of the map. The same as `keys.foreach(f)`, but may * be more efficient. * * @param f The loop body */ - final def foreachKey(f : Int => Unit) : Unit = this match { - case IntMap.Bin(_, _, left, right) => {left.foreachKey(f); right.foreachKey(f); } - case IntMap.Tip(key, _) => f(key); - case IntMap.Nil => {} + final def foreachKey(f: Int => Unit): Unit = this match { + case IntMap.Bin(_, _, left, right) => { left.foreachKey(f); right.foreachKey(f) } + case IntMap.Tip(key, _) => f(key) + case IntMap.Nil => } - override def valuesIterator : Iterator[T] = this match { - case IntMap.Nil => Iterator.empty; - case _ => new IntMapValueIterator(this); + override def valuesIterator: Iterator[T] = this match { + case IntMap.Nil => Iterator.empty + case _ => new IntMapValueIterator(this) } /** - * Loop over the keys of the map. The same as keys.foreach(f), but may + * Loop over the keys of the map. The same as `keys.foreach(f)`, but may * be more efficient. * * @param f The loop body */ - final def foreachValue(f : T => Unit) : Unit = this match { - case IntMap.Bin(_, _, left, right) => {left.foreachValue(f); right.foreachValue(f); } - case IntMap.Tip(_, value) => f(value); - case IntMap.Nil => {}; + final def foreachValue(f: T => Unit): Unit = this match { + case IntMap.Bin(_, _, left, right) => { left.foreachValue(f); right.foreachValue(f) } + case IntMap.Tip(_, value) => f(value) + case IntMap.Nil => } override def stringPrefix = "IntMap" - override def isEmpty = this == IntMap.Nil; + override def isEmpty = this == IntMap.Nil - override def filter(f : ((Int, T)) => Boolean) : IntMap[T] = this match { + override def filter(f: ((Int, T)) => Boolean): IntMap[T] = this match { case IntMap.Bin(prefix, mask, left, right) => { - val (newleft, newright) = (left.filter(f), right.filter(f)); - if ((left eq newleft) && (right eq newright)) this; - else bin(prefix, mask, newleft, newright); + val (newleft, newright) = (left.filter(f), right.filter(f)) + if ((left eq newleft) && (right eq newright)) this + else bin(prefix, mask, newleft, newright) } case IntMap.Tip(key, value) => if (f((key, value))) this - else IntMap.Nil; - case IntMap.Nil => IntMap.Nil; + else IntMap.Nil + case IntMap.Nil => IntMap.Nil } - def transform[S](f : (Int, T) => S) : IntMap[S] = this match { - case b@IntMap.Bin(prefix, mask, left, right) => b.bin(left.transform(f), right.transform(f)); - case t@IntMap.Tip(key, value) => t.withValue(f(key, value)); - case IntMap.Nil => IntMap.Nil; + def transform[S](f: (Int, T) => S): IntMap[S] = this match { + case b@IntMap.Bin(prefix, mask, left, right) => b.bin(left.transform(f), right.transform(f)) + case t@IntMap.Tip(key, value) => t.withValue(f(key, value)) + case IntMap.Nil => IntMap.Nil } - final override def size : Int = this match { - case IntMap.Nil => 0; - case IntMap.Tip(_, _) => 1; - case IntMap.Bin(_, _, left, right) => left.size + right.size; + final override def size: Int = this match { + case IntMap.Nil => 0 + case IntMap.Tip(_, _) => 1 + case IntMap.Bin(_, _, left, right) => left.size + right.size } - final def get(key : Int) : Option[T] = this match { - case IntMap.Bin(prefix, mask, left, right) => if (zero(key, mask)) left.get(key) else right.get(key); - case IntMap.Tip(key2, value) => if (key == key2) Some(value) else None; - case IntMap.Nil => None; + final def get(key: Int): Option[T] = this match { + case IntMap.Bin(prefix, mask, left, right) => if (zero(key, mask)) left.get(key) else right.get(key) + case IntMap.Tip(key2, value) => if (key == key2) Some(value) else None + case IntMap.Nil => None } - final override def getOrElse[S >: T](key : Int, default : =>S) : S = this match { - case IntMap.Nil => default; - case IntMap.Tip(key2, value) => if (key == key2) value else default; - case IntMap.Bin(prefix, mask, left, right) => if (zero(key, mask)) left.getOrElse(key, default) else right.getOrElse(key, default); + final override def getOrElse[S >: T](key: Int, default: => S): S = this match { + case IntMap.Nil => default + case IntMap.Tip(key2, value) => if (key == key2) value else default + case IntMap.Bin(prefix, mask, left, right) => + if (zero(key, mask)) left.getOrElse(key, default) else right.getOrElse(key, default) } - final override def apply(key : Int) : T = this match { - case IntMap.Bin(prefix, mask, left, right) => if (zero(key, mask)) left(key) else right(key); - case IntMap.Tip(key2, value) => if (key == key2) value else sys.error("Key not found"); - case IntMap.Nil => sys.error("key not found"); + final override def apply(key: Int): T = this match { + case IntMap.Bin(prefix, mask, left, right) => if (zero(key, mask)) left(key) else right(key) + case IntMap.Tip(key2, value) => if (key == key2) value else sys.error("Key not found") + case IntMap.Nil => sys.error("key not found") } def + [S >: T] (kv: (Int, S)): IntMap[S] = updated(kv._1, kv._2) - override def updated[S >: T](key : Int, value : S) : IntMap[S] = this match { - case IntMap.Bin(prefix, mask, left, right) => if (!hasMatch(key, prefix, mask)) join(key, IntMap.Tip(key, value), prefix, this); - else if (zero(key, mask)) IntMap.Bin(prefix, mask, left.updated(key, value), right) - else IntMap.Bin(prefix, mask, left, right.updated(key, value)); - case IntMap.Tip(key2, value2) => if (key == key2) IntMap.Tip(key, value); - else join(key, IntMap.Tip(key, value), key2, this); - case IntMap.Nil => IntMap.Tip(key, value); + override def updated[S >: T](key: Int, value: S): IntMap[S] = this match { + case IntMap.Bin(prefix, mask, left, right) => + if (!hasMatch(key, prefix, mask)) join(key, IntMap.Tip(key, value), prefix, this) + else if (zero(key, mask)) IntMap.Bin(prefix, mask, left.updated(key, value), right) + else IntMap.Bin(prefix, mask, left, right.updated(key, value)) + case IntMap.Tip(key2, value2) => + if (key == key2) IntMap.Tip(key, value) + else join(key, IntMap.Tip(key, value), key2, this) + case IntMap.Nil => IntMap.Tip(key, value) } /** @@ -284,7 +286,7 @@ extends AbstractMap[Int, T] * Equivalent to: * {{{ * this.get(key) match { - * case None => this.update(key, value); + * case None => this.update(key, value) * case Some(oldvalue) => this.update(key, f(oldvalue, value) * } * }}} @@ -295,24 +297,26 @@ extends AbstractMap[Int, T] * @param f The function used to resolve conflicts. * @return The updated map. */ - def updateWith[S >: T](key : Int, value : S, f : (T, S) => S) : IntMap[S] = this match { - case IntMap.Bin(prefix, mask, left, right) => if (!hasMatch(key, prefix, mask)) join(key, IntMap.Tip(key, value), prefix, this); - else if (zero(key, mask)) IntMap.Bin(prefix, mask, left.updateWith(key, value, f), right) - else IntMap.Bin(prefix, mask, left, right.updateWith(key, value, f)); - case IntMap.Tip(key2, value2) => if (key == key2) IntMap.Tip(key, f(value2, value)); - else join(key, IntMap.Tip(key, value), key2, this); - case IntMap.Nil => IntMap.Tip(key, value); + def updateWith[S >: T](key: Int, value: S, f: (T, S) => S): IntMap[S] = this match { + case IntMap.Bin(prefix, mask, left, right) => + if (!hasMatch(key, prefix, mask)) join(key, IntMap.Tip(key, value), prefix, this) + else if (zero(key, mask)) IntMap.Bin(prefix, mask, left.updateWith(key, value, f), right) + else IntMap.Bin(prefix, mask, left, right.updateWith(key, value, f)) + case IntMap.Tip(key2, value2) => + if (key == key2) IntMap.Tip(key, f(value2, value)) + else join(key, IntMap.Tip(key, value), key2, this) + case IntMap.Nil => IntMap.Tip(key, value) } - def - (key : Int) : IntMap[T] = this match { + def - (key: Int): IntMap[T] = this match { case IntMap.Bin(prefix, mask, left, right) => - if (!hasMatch(key, prefix, mask)) this; - else if (zero(key, mask)) bin(prefix, mask, left - key, right); - else bin(prefix, mask, left, right - key); + if (!hasMatch(key, prefix, mask)) this + else if (zero(key, mask)) bin(prefix, mask, left - key, right) + else bin(prefix, mask, left, right - key) case IntMap.Tip(key2, _) => - if (key == key2) IntMap.Nil; - else this; - case IntMap.Nil => IntMap.Nil; + if (key == key2) IntMap.Nil + else this + case IntMap.Nil => IntMap.Nil } /** @@ -324,7 +328,7 @@ extends AbstractMap[Int, T] * @param f The transforming function. * @return The modified map. */ - def modifyOrRemove[S](f : (Int, T) => Option[S]) : IntMap[S] = this match { + def modifyOrRemove[S](f: (Int, T) => Option[S]): IntMap[S] = this match { case IntMap.Bin(prefix, mask, left, right) => val newleft = left.modifyOrRemove(f) val newright = right.modifyOrRemove(f) @@ -350,25 +354,25 @@ extends AbstractMap[Int, T] * @param f The function used to resolve conflicts between two mappings. * @return Union of `this` and `that`, with identical key conflicts resolved using the function `f`. */ - def unionWith[S >: T](that : IntMap[S], f : (Int, S, S) => S) : IntMap[S] = (this, that) match{ + def unionWith[S >: T](that: IntMap[S], f: (Int, S, S) => S): IntMap[S] = (this, that) match{ case (IntMap.Bin(p1, m1, l1, r1), that@(IntMap.Bin(p2, m2, l2, r2))) => if (shorter(m1, m2)) { - if (!hasMatch(p2, p1, m1)) join[S](p1, this, p2, that); // TODO: remove [S] when SI-5548 is fixed - else if (zero(p2, m1)) IntMap.Bin(p1, m1, l1.unionWith(that, f), r1); - else IntMap.Bin(p1, m1, l1, r1.unionWith(that, f)); + if (!hasMatch(p2, p1, m1)) join[S](p1, this, p2, that) // TODO: remove [S] when SI-5548 is fixed + else if (zero(p2, m1)) IntMap.Bin(p1, m1, l1.unionWith(that, f), r1) + else IntMap.Bin(p1, m1, l1, r1.unionWith(that, f)) } else if (shorter(m2, m1)){ - if (!hasMatch(p1, p2, m2)) join[S](p1, this, p2, that); // TODO: remove [S] when SI-5548 is fixed - else if (zero(p1, m2)) IntMap.Bin(p2, m2, this.unionWith(l2, f), r2); - else IntMap.Bin(p2, m2, l2, this.unionWith(r2, f)); + if (!hasMatch(p1, p2, m2)) join[S](p1, this, p2, that) // TODO: remove [S] when SI-5548 is fixed + else if (zero(p1, m2)) IntMap.Bin(p2, m2, this.unionWith(l2, f), r2) + else IntMap.Bin(p2, m2, l2, this.unionWith(r2, f)) } else { - if (p1 == p2) IntMap.Bin(p1, m1, l1.unionWith(l2,f), r1.unionWith(r2, f)); - else join[S](p1, this, p2, that); // TODO: remove [S] when SI-5548 is fixed + if (p1 == p2) IntMap.Bin(p1, m1, l1.unionWith(l2,f), r1.unionWith(r2, f)) + else join[S](p1, this, p2, that) // TODO: remove [S] when SI-5548 is fixed } - case (IntMap.Tip(key, value), x) => x.updateWith[S](key, value, (x, y) => f(key, y, x)); - case (x, IntMap.Tip(key, value)) => x.updateWith[S](key, value, (x, y) => f(key, x, y)); - case (IntMap.Nil, x) => x; - case (x, IntMap.Nil) => x; + case (IntMap.Tip(key, value), x) => x.updateWith[S](key, value, (x, y) => f(key, y, x)) + case (x, IntMap.Tip(key, value)) => x.updateWith[S](key, value, (x, y) => f(key, x, y)) + case (IntMap.Nil, x) => x + case (x, IntMap.Nil) => x } /** @@ -382,13 +386,13 @@ extends AbstractMap[Int, T] * @param f The combining function. * @return Intersection of `this` and `that`, with values for identical keys produced by function `f`. */ - def intersectionWith[S, R](that : IntMap[S], f : (Int, T, S) => R) : IntMap[R] = (this, that) match { + def intersectionWith[S, R](that: IntMap[S], f: (Int, T, S) => R): IntMap[R] = (this, that) match { case (IntMap.Bin(p1, m1, l1, r1), that@IntMap.Bin(p2, m2, l2, r2)) => if (shorter(m1, m2)) { if (!hasMatch(p2, p1, m1)) IntMap.Nil else if (zero(p2, m1)) l1.intersectionWith(that, f) else r1.intersectionWith(that, f) - } else if (m1 == m2) bin(p1, m1, l1.intersectionWith(l2, f), r1.intersectionWith(r2, f)); + } else if (m1 == m2) bin(p1, m1, l1.intersectionWith(l2, f), r1.intersectionWith(r2, f)) else { if (!hasMatch(p1, p2, m2)) IntMap.Nil else if (zero(p1, m2)) this.intersectionWith(l2, f) @@ -413,15 +417,16 @@ extends AbstractMap[Int, T] * @param that The map to intersect with. * @return A map with all the keys both in `this` and `that`, mapped to corresponding values from `this`. */ - def intersection[R](that : IntMap[R]) : IntMap[T] = this.intersectionWith(that, (key : Int, value : T, value2 : R) => value); + def intersection[R](that: IntMap[R]): IntMap[T] = + this.intersectionWith(that, (key: Int, value: T, value2: R) => value) - def ++[S >: T](that : IntMap[S]) = + def ++[S >: T](that: IntMap[S]) = this.unionWith[S](that, (key, x, y) => y) /** * The entry with the lowest key value considered in unsigned order. */ - final def firstKey : Int = this match { + final def firstKey: Int = this match { case Bin(_, _, l, r) => l.firstKey case Tip(k, v) => k case IntMap.Nil => sys.error("Empty set") @@ -430,7 +435,7 @@ extends AbstractMap[Int, T] /** * The entry with the highest key value considered in unsigned order. */ - final def lastKey : Int = this match { + final def lastKey: Int = this match { case Bin(_, _, l, r) => r.lastKey case Tip(k, v) => k case IntMap.Nil => sys.error("Empty set") diff --git a/src/library/scala/collection/immutable/LongMap.scala b/src/library/scala/collection/immutable/LongMap.scala index 8a316f37de..002027b162 100644 --- a/src/library/scala/collection/immutable/LongMap.scala +++ b/src/library/scala/collection/immutable/LongMap.scala @@ -18,17 +18,17 @@ import scala.collection.mutable.{ Builder, MapBuilder } private[immutable] object LongMapUtils extends BitOperations.Long { def branchMask(i: Long, j: Long) = highestOneBit(i ^ j) - def join[T](p1 : Long, t1 : LongMap[T], p2 : Long, t2 : LongMap[T]) : LongMap[T] = { - val m = branchMask(p1, p2); - val p = mask(p1, m); + def join[T](p1: Long, t1: LongMap[T], p2: Long, t2: LongMap[T]): LongMap[T] = { + val m = branchMask(p1, p2) + val p = mask(p1, m) if (zero(p1, m)) LongMap.Bin(p, m, t1, t2) - else LongMap.Bin(p, m, t2, t1); + else LongMap.Bin(p, m, t2, t1) } - def bin[T](prefix : Long, mask : Long, left : LongMap[T], right : LongMap[T]) : LongMap[T] = (left, right) match { - case (left, LongMap.Nil) => left; - case (LongMap.Nil, right) => right; - case (left, right) => LongMap.Bin(prefix, mask, left, right); + def bin[T](prefix: Long, mask: Long, left: LongMap[T], right: LongMap[T]): LongMap[T] = (left, right) match { + case (left, LongMap.Nil) => left + case (LongMap.Nil, right) => right + case (left, right) => LongMap.Bin(prefix, mask, left, right) } } @@ -49,29 +49,29 @@ object LongMap { def apply(): Builder[(Long, B), LongMap[B]] = new MapBuilder[Long, B, LongMap[B]](empty[B]) } - def empty[T] : LongMap[T] = LongMap.Nil; - def singleton[T](key : Long, value : T) : LongMap[T] = LongMap.Tip(key, value); - def apply[T](elems : (Long, T)*) : LongMap[T] = - elems.foldLeft(empty[T])((x, y) => x.updated(y._1, y._2)); + def empty[T]: LongMap[T] = LongMap.Nil + def singleton[T](key: Long, value: T): LongMap[T] = LongMap.Tip(key, value) + def apply[T](elems: (Long, T)*): LongMap[T] = + elems.foldLeft(empty[T])((x, y) => x.updated(y._1, y._2)) private[immutable] case object Nil extends LongMap[Nothing] { // Important, don't remove this! See IntMap for explanation. override def equals(that : Any) = that match { - case (that : AnyRef) if (this eq that) => true; - case (that : LongMap[_]) => false; // The only empty LongMaps are eq Nil - case that => super.equals(that); + case (that: AnyRef) if (this eq that) => true + case (that: LongMap[_]) => false // The only empty LongMaps are eq Nil + case that => super.equals(that) } - }; + } - private[immutable] case class Tip[+T](key : Long, value : T) extends LongMap[T]{ - def withValue[S](s : S) = - if (s.asInstanceOf[AnyRef] eq value.asInstanceOf[AnyRef]) this.asInstanceOf[LongMap.Tip[S]]; - else LongMap.Tip(key, s); + private[immutable] case class Tip[+T](key: Long, value: T) extends LongMap[T] { + def withValue[S](s: S) = + if (s.asInstanceOf[AnyRef] eq value.asInstanceOf[AnyRef]) this.asInstanceOf[LongMap.Tip[S]] + else LongMap.Tip(key, s) } - private[immutable] case class Bin[+T](prefix : Long, mask : Long, left : LongMap[T], right : LongMap[T]) extends LongMap[T]{ - def bin[S](left : LongMap[S], right : LongMap[S]) : LongMap[S] = { - if ((this.left eq left) && (this.right eq right)) this.asInstanceOf[LongMap.Bin[S]]; - else LongMap.Bin[S](prefix, mask, left, right); + private[immutable] case class Bin[+T](prefix: Long, mask: Long, left: LongMap[T], right: LongMap[T]) extends LongMap[T] { + def bin[S](left: LongMap[S], right: LongMap[S]): LongMap[S] = { + if ((this.left eq left) && (this.right eq right)) this.asInstanceOf[LongMap.Bin[S]] + else LongMap.Bin[S](prefix, mask, left, right) } } } @@ -79,64 +79,62 @@ object LongMap { import LongMap._ // Iterator over a non-empty LongMap. -private[immutable] abstract class LongMapIterator[V, T](it : LongMap[V]) extends AbstractIterator[T] { +private[immutable] abstract class LongMapIterator[V, T](it: LongMap[V]) extends AbstractIterator[T] { // Basically this uses a simple stack to emulate conversion over the tree. However // because we know that Longs are only 64 bits we can have at most 64 LongMap.Bins and // one LongMap.Tip sitting on the tree at any point. Therefore we know the maximum stack // depth is 65 - var index = 0; - var buffer = new Array[AnyRef](65); + var index = 0 + var buffer = new Array[AnyRef](65) def pop() = { - index -= 1; - buffer(index).asInstanceOf[LongMap[V]]; + index -= 1 + buffer(index).asInstanceOf[LongMap[V]] } - def push(x : LongMap[V]) { - buffer(index) = x.asInstanceOf[AnyRef]; - index += 1; + def push(x: LongMap[V]) { + buffer(index) = x.asInstanceOf[AnyRef] + index += 1 } push(it); /** * What value do we assign to a tip? */ - def valueOf(tip : LongMap.Tip[V]) : T; + def valueOf(tip: LongMap.Tip[V]): T - def hasNext = index != 0; - final def next : T = + def hasNext = index != 0 + final def next: T = pop() match { case LongMap.Bin(_,_, t@LongMap.Tip(_, _), right) => { - push(right); - valueOf(t); + push(right) + valueOf(t) } case LongMap.Bin(_, _, left, right) => { - push(right); - push(left); - next; + push(right) + push(left) + next } - case t@LongMap.Tip(_, _) => valueOf(t); + case t@LongMap.Tip(_, _) => valueOf(t) // This should never happen. We don't allow LongMap.Nil in subtrees of the LongMap // and don't return an LongMapIterator for LongMap.Nil. - case LongMap.Nil => sys.error("Empty maps not allowed as subtrees"); + case LongMap.Nil => sys.error("Empty maps not allowed as subtrees") } } -private[immutable] class LongMapEntryIterator[V](it : LongMap[V]) extends LongMapIterator[V, (Long, V)](it){ - def valueOf(tip : LongMap.Tip[V]) = (tip.key, tip.value); +private[immutable] class LongMapEntryIterator[V](it: LongMap[V]) extends LongMapIterator[V, (Long, V)](it){ + def valueOf(tip: LongMap.Tip[V]) = (tip.key, tip.value) } -private[immutable] class LongMapValueIterator[V](it : LongMap[V]) extends LongMapIterator[V, V](it){ - def valueOf(tip : LongMap.Tip[V]) = tip.value; +private[immutable] class LongMapValueIterator[V](it: LongMap[V]) extends LongMapIterator[V, V](it){ + def valueOf(tip: LongMap.Tip[V]) = tip.value } -private[immutable] class LongMapKeyIterator[V](it : LongMap[V]) extends LongMapIterator[V, Long](it){ - def valueOf(tip : LongMap.Tip[V]) = tip.key; +private[immutable] class LongMapKeyIterator[V](it: LongMap[V]) extends LongMapIterator[V, Long](it){ + def valueOf(tip: LongMap.Tip[V]) = tip.key } -import LongMap._; - /** * Specialised immutable map structure for long keys, based on * <a href="http://citeseer.ist.psu.edu/okasaki98fast.html">Fast Mergeable Long Maps</a> @@ -157,12 +155,12 @@ extends AbstractMap[Long, T] with Map[Long, T] with MapLike[Long, T, LongMap[T]] { - override def empty: LongMap[T] = LongMap.Nil; + override def empty: LongMap[T] = LongMap.Nil override def toList = { - val buffer = new scala.collection.mutable.ListBuffer[(Long, T)]; - foreach(buffer += _); - buffer.toList; + val buffer = new scala.collection.mutable.ListBuffer[(Long, T)] + foreach(buffer += _) + buffer.toList } /** @@ -171,22 +169,22 @@ extends AbstractMap[Long, T] * @return an iterator over pairs of long keys and corresponding values. */ def iterator: Iterator[(Long, T)] = this match { - case LongMap.Nil => Iterator.empty; - case _ => new LongMapEntryIterator(this); + case LongMap.Nil => Iterator.empty + case _ => new LongMapEntryIterator(this) } /** * Loops over the key, value pairs of the map in unsigned order of the keys. */ - override final def foreach[U](f : ((Long, T)) => U) : Unit = this match { - case LongMap.Bin(_, _, left, right) => {left.foreach(f); right.foreach(f); } + override final def foreach[U](f: ((Long, T)) => U): Unit = this match { + case LongMap.Bin(_, _, left, right) => { left.foreach(f); right.foreach(f) } case LongMap.Tip(key, value) => f((key, value)); - case LongMap.Nil => {}; + case LongMap.Nil => } - override def keysIterator : Iterator[Long] = this match { - case LongMap.Nil => Iterator.empty; - case _ => new LongMapKeyIterator(this); + override def keysIterator: Iterator[Long] = this match { + case LongMap.Nil => Iterator.empty + case _ => new LongMapKeyIterator(this) } /** @@ -195,15 +193,15 @@ extends AbstractMap[Long, T] * * @param f The loop body */ - final def foreachKey(f : Long => Unit) : Unit = this match { - case LongMap.Bin(_, _, left, right) => {left.foreachKey(f); right.foreachKey(f); } - case LongMap.Tip(key, _) => f(key); - case LongMap.Nil => {} + final def foreachKey(f: Long => Unit): Unit = this match { + case LongMap.Bin(_, _, left, right) => { left.foreachKey(f); right.foreachKey(f) } + case LongMap.Tip(key, _) => f(key) + case LongMap.Nil => } - override def valuesIterator : Iterator[T] = this match { - case LongMap.Nil => Iterator.empty; - case _ => new LongMapValueIterator(this); + override def valuesIterator: Iterator[T] = this match { + case LongMap.Nil => Iterator.empty + case _ => new LongMapValueIterator(this) } /** @@ -212,67 +210,70 @@ extends AbstractMap[Long, T] * * @param f The loop body */ - final def foreachValue(f : T => Unit) : Unit = this match { - case LongMap.Bin(_, _, left, right) => {left.foreachValue(f); right.foreachValue(f); } - case LongMap.Tip(_, value) => f(value); - case LongMap.Nil => {}; + final def foreachValue(f: T => Unit): Unit = this match { + case LongMap.Bin(_, _, left, right) => { left.foreachValue(f); right.foreachValue(f) } + case LongMap.Tip(_, value) => f(value) + case LongMap.Nil => } override def stringPrefix = "LongMap" - override def isEmpty = this == LongMap.Nil; + override def isEmpty = this == LongMap.Nil - override def filter(f : ((Long, T)) => Boolean) : LongMap[T] = this match { + override def filter(f: ((Long, T)) => Boolean): LongMap[T] = this match { case LongMap.Bin(prefix, mask, left, right) => { - val (newleft, newright) = (left.filter(f), right.filter(f)); - if ((left eq newleft) && (right eq newright)) this; - else bin(prefix, mask, newleft, newright); + val (newleft, newright) = (left.filter(f), right.filter(f)) + if ((left eq newleft) && (right eq newright)) this + else bin(prefix, mask, newleft, newright) } case LongMap.Tip(key, value) => if (f((key, value))) this - else LongMap.Nil; - case LongMap.Nil => LongMap.Nil; + else LongMap.Nil + case LongMap.Nil => LongMap.Nil } - def transform[S](f : (Long, T) => S) : LongMap[S] = this match { - case b@LongMap.Bin(prefix, mask, left, right) => b.bin(left.transform(f), right.transform(f)); - case t@LongMap.Tip(key, value) => t.withValue(f(key, value)); - case LongMap.Nil => LongMap.Nil; + def transform[S](f: (Long, T) => S): LongMap[S] = this match { + case b@LongMap.Bin(prefix, mask, left, right) => b.bin(left.transform(f), right.transform(f)) + case t@LongMap.Tip(key, value) => t.withValue(f(key, value)) + case LongMap.Nil => LongMap.Nil } - final override def size : Int = this match { - case LongMap.Nil => 0; - case LongMap.Tip(_, _) => 1; - case LongMap.Bin(_, _, left, right) => left.size + right.size; + final override def size: Int = this match { + case LongMap.Nil => 0 + case LongMap.Tip(_, _) => 1 + case LongMap.Bin(_, _, left, right) => left.size + right.size } - final def get(key : Long) : Option[T] = this match { - case LongMap.Bin(prefix, mask, left, right) => if (zero(key, mask)) left.get(key) else right.get(key); - case LongMap.Tip(key2, value) => if (key == key2) Some(value) else None; - case LongMap.Nil => None; + final def get(key: Long): Option[T] = this match { + case LongMap.Bin(prefix, mask, left, right) => if (zero(key, mask)) left.get(key) else right.get(key) + case LongMap.Tip(key2, value) => if (key == key2) Some(value) else None + case LongMap.Nil => None } - final override def getOrElse[S >: T](key : Long, default : =>S) : S = this match { - case LongMap.Nil => default; - case LongMap.Tip(key2, value) => if (key == key2) value else default; - case LongMap.Bin(prefix, mask, left, right) => if (zero(key, mask)) left.getOrElse(key, default) else right.getOrElse(key, default); + final override def getOrElse[S >: T](key: Long, default: => S): S = this match { + case LongMap.Nil => default + case LongMap.Tip(key2, value) => if (key == key2) value else default + case LongMap.Bin(prefix, mask, left, right) => + if (zero(key, mask)) left.getOrElse(key, default) else right.getOrElse(key, default) } - final override def apply(key : Long) : T = this match { - case LongMap.Bin(prefix, mask, left, right) => if (zero(key, mask)) left(key) else right(key); - case LongMap.Tip(key2, value) => if (key == key2) value else sys.error("Key not found"); - case LongMap.Nil => sys.error("key not found"); + final override def apply(key: Long): T = this match { + case LongMap.Bin(prefix, mask, left, right) => if (zero(key, mask)) left(key) else right(key) + case LongMap.Tip(key2, value) => if (key == key2) value else sys.error("Key not found") + case LongMap.Nil => sys.error("key not found") } def + [S >: T] (kv: (Long, S)): LongMap[S] = updated(kv._1, kv._2) - override def updated[S >: T](key : Long, value : S) : LongMap[S] = this match { - case LongMap.Bin(prefix, mask, left, right) => if (!hasMatch(key, prefix, mask)) join(key, LongMap.Tip(key, value), prefix, this); - else if (zero(key, mask)) LongMap.Bin(prefix, mask, left.updated(key, value), right) - else LongMap.Bin(prefix, mask, left, right.updated(key, value)); - case LongMap.Tip(key2, value2) => if (key == key2) LongMap.Tip(key, value); - else join(key, LongMap.Tip(key, value), key2, this); - case LongMap.Nil => LongMap.Tip(key, value); + override def updated[S >: T](key: Long, value: S): LongMap[S] = this match { + case LongMap.Bin(prefix, mask, left, right) => + if (!hasMatch(key, prefix, mask)) join(key, LongMap.Tip(key, value), prefix, this) + else if (zero(key, mask)) LongMap.Bin(prefix, mask, left.updated(key, value), right) + else LongMap.Bin(prefix, mask, left, right.updated(key, value)) + case LongMap.Tip(key2, value2) => + if (key == key2) LongMap.Tip(key, value) + else join(key, LongMap.Tip(key, value), key2, this) + case LongMap.Nil => LongMap.Tip(key, value) } /** @@ -281,7 +282,7 @@ extends AbstractMap[Long, T] * Equivalent to * {{{ * this.get(key) match { - * case None => this.update(key, value); + * case None => this.update(key, value) * case Some(oldvalue) => this.update(key, f(oldvalue, value) * } * }}} @@ -292,24 +293,26 @@ extends AbstractMap[Long, T] * @param f The function used to resolve conflicts. * @return The updated map. */ - def updateWith[S >: T](key : Long, value : S, f : (T, S) => S) : LongMap[S] = this match { - case LongMap.Bin(prefix, mask, left, right) => if (!hasMatch(key, prefix, mask)) join(key, LongMap.Tip(key, value), prefix, this); - else if (zero(key, mask)) LongMap.Bin(prefix, mask, left.updateWith(key, value, f), right) - else LongMap.Bin(prefix, mask, left, right.updateWith(key, value, f)); - case LongMap.Tip(key2, value2) => if (key == key2) LongMap.Tip(key, f(value2, value)); - else join(key, LongMap.Tip(key, value), key2, this); - case LongMap.Nil => LongMap.Tip(key, value); + def updateWith[S >: T](key: Long, value: S, f: (T, S) => S): LongMap[S] = this match { + case LongMap.Bin(prefix, mask, left, right) => + if (!hasMatch(key, prefix, mask)) join(key, LongMap.Tip(key, value), prefix, this) + else if (zero(key, mask)) LongMap.Bin(prefix, mask, left.updateWith(key, value, f), right) + else LongMap.Bin(prefix, mask, left, right.updateWith(key, value, f)) + case LongMap.Tip(key2, value2) => + if (key == key2) LongMap.Tip(key, f(value2, value)) + else join(key, LongMap.Tip(key, value), key2, this) + case LongMap.Nil => LongMap.Tip(key, value) } - def -(key : Long) : LongMap[T] = this match { + def -(key: Long): LongMap[T] = this match { case LongMap.Bin(prefix, mask, left, right) => - if (!hasMatch(key, prefix, mask)) this; - else if (zero(key, mask)) bin(prefix, mask, left - key, right); - else bin(prefix, mask, left, right - key); + if (!hasMatch(key, prefix, mask)) this + else if (zero(key, mask)) bin(prefix, mask, left - key, right) + else bin(prefix, mask, left, right - key) case LongMap.Tip(key2, _) => - if (key == key2) LongMap.Nil; - else this; - case LongMap.Nil => LongMap.Nil; + if (key == key2) LongMap.Nil + else this + case LongMap.Nil => LongMap.Nil } /** @@ -321,21 +324,21 @@ extends AbstractMap[Long, T] * @param f The transforming function. * @return The modified map. */ - def modifyOrRemove[S](f : (Long, T) => Option[S]) : LongMap[S] = this match { + def modifyOrRemove[S](f: (Long, T) => Option[S]): LongMap[S] = this match { case LongMap.Bin(prefix, mask, left, right) => { - val newleft = left.modifyOrRemove(f); - val newright = right.modifyOrRemove(f); - if ((left eq newleft) && (right eq newright)) this.asInstanceOf[LongMap[S]]; + val newleft = left.modifyOrRemove(f) + val newright = right.modifyOrRemove(f) + if ((left eq newleft) && (right eq newright)) this.asInstanceOf[LongMap[S]] else bin(prefix, mask, newleft, newright) } case LongMap.Tip(key, value) => f(key, value) match { - case None => LongMap.Nil; + case None => LongMap.Nil case Some(value2) => //hack to preserve sharing if (value.asInstanceOf[AnyRef] eq value2.asInstanceOf[AnyRef]) this.asInstanceOf[LongMap[S]] - else LongMap.Tip(key, value2); + else LongMap.Tip(key, value2) } - case LongMap.Nil => LongMap.Nil; + case LongMap.Nil => LongMap.Nil } /** @@ -346,25 +349,25 @@ extends AbstractMap[Long, T] * @param f The function used to resolve conflicts between two mappings. * @return Union of `this` and `that`, with identical key conflicts resolved using the function `f`. */ - def unionWith[S >: T](that : LongMap[S], f : (Long, S, S) => S) : LongMap[S] = (this, that) match{ + def unionWith[S >: T](that: LongMap[S], f: (Long, S, S) => S): LongMap[S] = (this, that) match{ case (LongMap.Bin(p1, m1, l1, r1), that@(LongMap.Bin(p2, m2, l2, r2))) => if (shorter(m1, m2)) { - if (!hasMatch(p2, p1, m1)) join[S](p1, this, p2, that); // TODO: remove [S] when SI-5548 is fixed - else if (zero(p2, m1)) LongMap.Bin(p1, m1, l1.unionWith(that, f), r1); - else LongMap.Bin(p1, m1, l1, r1.unionWith(that, f)); + if (!hasMatch(p2, p1, m1)) join[S](p1, this, p2, that) // TODO: remove [S] when SI-5548 is fixed + else if (zero(p2, m1)) LongMap.Bin(p1, m1, l1.unionWith(that, f), r1) + else LongMap.Bin(p1, m1, l1, r1.unionWith(that, f)) } else if (shorter(m2, m1)){ - if (!hasMatch(p1, p2, m2)) join[S](p1, this, p2, that); // TODO: remove [S] when SI-5548 is fixed - else if (zero(p1, m2)) LongMap.Bin(p2, m2, this.unionWith(l2, f), r2); - else LongMap.Bin(p2, m2, l2, this.unionWith(r2, f)); + if (!hasMatch(p1, p2, m2)) join[S](p1, this, p2, that) // TODO: remove [S] when SI-5548 is fixed + else if (zero(p1, m2)) LongMap.Bin(p2, m2, this.unionWith(l2, f), r2) + else LongMap.Bin(p2, m2, l2, this.unionWith(r2, f)) } else { - if (p1 == p2) LongMap.Bin(p1, m1, l1.unionWith(l2,f), r1.unionWith(r2, f)); - else join[S](p1, this, p2, that); // TODO: remove [S] when SI-5548 is fixed + if (p1 == p2) LongMap.Bin(p1, m1, l1.unionWith(l2,f), r1.unionWith(r2, f)) + else join[S](p1, this, p2, that) // TODO: remove [S] when SI-5548 is fixed } - case (LongMap.Tip(key, value), x) => x.updateWith[S](key, value, (x, y) => f(key, y, x)); // TODO: remove [S] when SI-5548 is fixed - case (x, LongMap.Tip(key, value)) => x.updateWith[S](key, value, (x, y) => f(key, x, y)); - case (LongMap.Nil, x) => x; - case (x, LongMap.Nil) => x; + case (LongMap.Tip(key, value), x) => x.updateWith[S](key, value, (x, y) => f(key, y, x)) // TODO: remove [S] when SI-5548 is fixed + case (x, LongMap.Tip(key, value)) => x.updateWith[S](key, value, (x, y) => f(key, x, y)) + case (LongMap.Nil, x) => x + case (x, LongMap.Nil) => x } /** @@ -378,27 +381,27 @@ extends AbstractMap[Long, T] * @param f The combining function. * @return Intersection of `this` and `that`, with values for identical keys produced by function `f`. */ - def intersectionWith[S, R](that : LongMap[S], f : (Long, T, S) => R) : LongMap[R] = (this, that) match { + def intersectionWith[S, R](that: LongMap[S], f: (Long, T, S) => R): LongMap[R] = (this, that) match { case (LongMap.Bin(p1, m1, l1, r1), that@LongMap.Bin(p2, m2, l2, r2)) => if (shorter(m1, m2)) { - if (!hasMatch(p2, p1, m1)) LongMap.Nil; - else if (zero(p2, m1)) l1.intersectionWith(that, f); - else r1.intersectionWith(that, f); - } else if (m1 == m2) bin(p1, m1, l1.intersectionWith(l2, f), r1.intersectionWith(r2, f)); + if (!hasMatch(p2, p1, m1)) LongMap.Nil + else if (zero(p2, m1)) l1.intersectionWith(that, f) + else r1.intersectionWith(that, f) + } else if (m1 == m2) bin(p1, m1, l1.intersectionWith(l2, f), r1.intersectionWith(r2, f)) else { - if (!hasMatch(p1, p2, m2)) LongMap.Nil; - else if (zero(p1, m2)) this.intersectionWith(l2, f); - else this.intersectionWith(r2, f); + if (!hasMatch(p1, p2, m2)) LongMap.Nil + else if (zero(p1, m2)) this.intersectionWith(l2, f) + else this.intersectionWith(r2, f) } case (LongMap.Tip(key, value), that) => that.get(key) match { - case None => LongMap.Nil; - case Some(value2) => LongMap.Tip(key, f(key, value, value2)); + case None => LongMap.Nil + case Some(value2) => LongMap.Tip(key, f(key, value, value2)) } case (_, LongMap.Tip(key, value)) => this.get(key) match { - case None => LongMap.Nil; - case Some(value2) => LongMap.Tip(key, f(key, value2, value)); + case None => LongMap.Nil + case Some(value2) => LongMap.Tip(key, f(key, value2, value)) } - case (_, _) => LongMap.Nil; + case (_, _) => LongMap.Nil } /** @@ -409,9 +412,10 @@ extends AbstractMap[Long, T] * @param that The map to intersect with. * @return A map with all the keys both in `this` and `that`, mapped to corresponding values from `this`. */ - def intersection[R](that : LongMap[R]) : LongMap[T] = this.intersectionWith(that, (key : Long, value : T, value2 : R) => value); + def intersection[R](that: LongMap[R]): LongMap[T] = + this.intersectionWith(that, (key: Long, value: T, value2: R) => value) - def ++[S >: T](that : LongMap[S]) = + def ++[S >: T](that: LongMap[S]) = this.unionWith[S](that, (key, x, y) => y) } diff --git a/src/library/scala/util/control/ControlThrowable.scala b/src/library/scala/util/control/ControlThrowable.scala index 8cbe3064ef..64afb1f10f 100644 --- a/src/library/scala/util/control/ControlThrowable.scala +++ b/src/library/scala/util/control/ControlThrowable.scala @@ -24,8 +24,9 @@ package scala.util.control * try { * // Body might throw arbitrarily * } catch { - * case ce : ControlThrowable => throw ce // propagate - * case t : Exception => log(t) // log and suppress + * case c: ControlThrowable => throw c // propagate + * case t: Exception => log(t) // log and suppress + * } * }}} * * @author Miles Sabin diff --git a/src/reflect/scala/reflect/api/Types.scala b/src/reflect/scala/reflect/api/Types.scala index b62a92cbd7..b797c71f6d 100644 --- a/src/reflect/scala/reflect/api/Types.scala +++ b/src/reflect/scala/reflect/api/Types.scala @@ -121,7 +121,7 @@ trait Types extends base.Types { self: Universe => * class C extends p.D[Int] * T.asSeenFrom(ThisType(C), D) (where D is owner of m) * = Int - * }}} + * }}} */ def asSeenFrom(pre: Type, clazz: Symbol): Type @@ -171,6 +171,15 @@ trait Types extends base.Types { self: Universe => */ def widen: Type + /** Map to a singleton type which is a subtype of this type. + * The fallback implemented here gives: + * {{{ + * T.narrow = (T {}).this.type + * }}} + * Overridden where we know more about where types come from. + */ + def narrow: Type + /** The string discriminator of this type; useful for debugging */ def kind: String } @@ -365,4 +374,3 @@ trait Types extends base.Types { self: Universe => */ def existentialAbstraction(tparams: List[Symbol], tpe0: Type): Type } - |