summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2007-07-24 17:43:47 +0000
committerMartin Odersky <odersky@gmail.com>2007-07-24 17:43:47 +0000
commit5355f3c7323fa0ea1dabe2e39ec112c9d0b061b9 (patch)
tree2bda3cd539639ca5387a2a2fcea922a4c7ee480a /src/library
parentd8504784b821fb64f411adf7c551ee4646e5f99c (diff)
downloadscala-5355f3c7323fa0ea1dabe2e39ec112c9d0b061b9.tar.gz
scala-5355f3c7323fa0ea1dabe2e39ec112c9d0b061b9.tar.bz2
scala-5355f3c7323fa0ea1dabe2e39ec112c9d0b061b9.zip
fixed problems in subtyping.
fixed unsafe isInstanceOf's
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/collection/immutable/ListSet.scala9
-rw-r--r--src/library/scala/collection/immutable/Stack.scala6
-rw-r--r--src/library/scala/collection/mutable/LinkedList.scala7
-rw-r--r--src/library/scala/collection/mutable/PriorityQueue.scala12
-rw-r--r--src/library/scala/collection/mutable/Queue.scala12
-rw-r--r--src/library/scala/collection/mutable/Stack.scala12
-rw-r--r--src/library/scala/reflect/Print.scala24
-rw-r--r--src/library/scala/xml/Utility.scala5
8 files changed, 51 insertions, 36 deletions
diff --git a/src/library/scala/collection/immutable/ListSet.scala b/src/library/scala/collection/immutable/ListSet.scala
index 6bf4d5b626..3945612143 100644
--- a/src/library/scala/collection/immutable/ListSet.scala
+++ b/src/library/scala/collection/immutable/ListSet.scala
@@ -86,12 +86,13 @@ class ListSet[A] extends AnyRef with Set[A] {
/** Compares two sets for equality.
* Two set are equal iff they contain the same elements.
*/
- override def equals(obj: Any): Boolean =
- if (obj.isInstanceOf[scala.collection.Set[A]]) {
+ override def equals(obj: Any): Boolean = obj match {
+ case _: scala.collection.Set[_] =>
val that = obj.asInstanceOf[scala.collection.Set[A]]
- if (size != that.size) false else toList.forall(that.contains)
- } else
+ (size == that.size) && (toList forall that.contains)
+ case _ =>
false
+ }
/**
* @throws Predef.NoSuchElementException
diff --git a/src/library/scala/collection/immutable/Stack.scala b/src/library/scala/collection/immutable/Stack.scala
index 22f257b99f..75d6cb8b98 100644
--- a/src/library/scala/collection/immutable/Stack.scala
+++ b/src/library/scala/collection/immutable/Stack.scala
@@ -106,8 +106,10 @@ class Stack[+A] extends Seq[A] {
* @return true, iff the two stacks are equal; i.e. they contain the
* same elements in the same order.
*/
- override def equals(obj: Any): Boolean =
- obj.isInstanceOf[Stack[A]] && sameElements(obj.asInstanceOf[Stack[A]])
+ override def equals(obj: Any): Boolean = obj match {
+ case that: Stack[_] => this sameElements that
+ case _ => false
+ }
/** Returns the hash code for this stack.
*
diff --git a/src/library/scala/collection/mutable/LinkedList.scala b/src/library/scala/collection/mutable/LinkedList.scala
index bd5ae23532..0ed1a02889 100644
--- a/src/library/scala/collection/mutable/LinkedList.scala
+++ b/src/library/scala/collection/mutable/LinkedList.scala
@@ -22,9 +22,10 @@ class LinkedList[A](var elem: A, var next: LinkedList[A])
extends SingleLinkedList[A, LinkedList[A]]
{
- override def equals(obj: Any): Boolean =
- obj.isInstanceOf[LinkedList[A]] &&
- toList.equals((obj.asInstanceOf[LinkedList[A]]).toList)
+ override def equals(obj: Any): Boolean = obj match {
+ case that: LinkedList[_] => this.toList equals that.toList
+ case _ => false
+ }
override protected def stringPrefix: String = "LinkedList"
}
diff --git a/src/library/scala/collection/mutable/PriorityQueue.scala b/src/library/scala/collection/mutable/PriorityQueue.scala
index 0772c545e9..de615469d8 100644
--- a/src/library/scala/collection/mutable/PriorityQueue.scala
+++ b/src/library/scala/collection/mutable/PriorityQueue.scala
@@ -153,12 +153,14 @@ class PriorityQueue[A <% Ordered[A]] extends ResizableArray[A] with CloneableCol
*
* @return true, iff both queues contain the same sequence of elements.
*/
- override def equals(that: Any): Boolean =
- that.isInstanceOf[PriorityQueue[A]] &&
- { val other = that.asInstanceOf[PriorityQueue[A]]
- elements.zip(other.elements).forall {
+ override def equals(obj: Any): Boolean = obj match {
+ case that: PriorityQueue[_] =>
+ (this.elements zip that.elements) forall {
case (thiselem, thatelem) => thiselem == thatelem
- }}
+ }
+ case _ =>
+ false
+ }
/** The hashCode method always yields an error, since it is not
* safe to use mutable queues as keys in hash tables.
diff --git a/src/library/scala/collection/mutable/Queue.scala b/src/library/scala/collection/mutable/Queue.scala
index d654a82888..e7c80ae7b4 100644
--- a/src/library/scala/collection/mutable/Queue.scala
+++ b/src/library/scala/collection/mutable/Queue.scala
@@ -166,12 +166,14 @@ class Queue[A] extends MutableList[A] with CloneableCollection {
*
* @return true, iff both queues contain the same sequence of elements.
*/
- override def equals(that: Any): Boolean =
- that.isInstanceOf[Queue[A]] &&
- { val other = that.asInstanceOf[Queue[A]]
- elements.zip(other.elements).forall {
+ override def equals(obj: Any): Boolean = obj match {
+ case that: Queue[_] =>
+ (this.elements zip that.elements) forall {
case (thiselem, thatelem) => thiselem == thatelem
- }}
+ }
+ case _ =>
+ false
+ }
/** The hashCode method always yields an error, since it is not
* safe to use mutable queues as keys in hash tables.
diff --git a/src/library/scala/collection/mutable/Stack.scala b/src/library/scala/collection/mutable/Stack.scala
index be95aee1a5..8aa2f27115 100644
--- a/src/library/scala/collection/mutable/Stack.scala
+++ b/src/library/scala/collection/mutable/Stack.scala
@@ -107,12 +107,14 @@ class Stack[A] extends MutableList[A] with CloneableCollection {
*
* @return true, iff both stacks contain the same sequence of elements.
*/
- override def equals(that: Any): Boolean =
- that.isInstanceOf[Stack[A]] &&
- { val other = that.asInstanceOf[Stack[A]];
- elements.zip(other.elements).forall {
+ override def equals(obj: Any): Boolean = obj match {
+ case that: Stack[_] =>
+ (this.elements zip that.elements) forall {
case (thiselem, thatelem) => thiselem == thatelem
- }}
+ }
+ case _ =>
+ false
+ }
/** The hashCode method always yields an error, since it is not
* safe to use mutable stacks as keys in hash tables.
diff --git a/src/library/scala/reflect/Print.scala b/src/library/scala/reflect/Print.scala
index 789d112490..039160077c 100644
--- a/src/library/scala/reflect/Print.scala
+++ b/src/library/scala/reflect/Print.scala
@@ -13,18 +13,20 @@ package scala.reflect
object Print extends Function1[Any, String] {
- def apply(any: Any): String =
- if (any.isInstanceOf[Code[Any]])
- apply(any.asInstanceOf[Code[Any]])
- else if (any.isInstanceOf[Tree])
- apply(any.asInstanceOf[Tree])
- else if (any.isInstanceOf[Symbol])
- apply(any.asInstanceOf[Symbol])
- else if (any.isInstanceOf[Type])
- apply(any.asInstanceOf[Type])
- else "UnknownAny"
+ def apply(any: Any): String = any match {
+ case x: Code[_] =>
+ apply(x)
+ case x: Tree =>
+ apply(x)
+ case x: Symbol =>
+ apply(x)
+ case x: Type =>
+ apply(x)
+ case _ =>
+ "UnknownAny"
+ }
- def apply(code: Code[Any]): String =
+ def apply[A](code: Code[A]): String =
Print(code.tree)
def apply(tree: Tree): String = tree match {
diff --git a/src/library/scala/xml/Utility.scala b/src/library/scala/xml/Utility.scala
index 00f93b9ffc..3f3ac9d6e8 100644
--- a/src/library/scala/xml/Utility.scala
+++ b/src/library/scala/xml/Utility.scala
@@ -219,7 +219,10 @@ object Utility extends AnyRef with parsing.TokenTests {
sb: StringBuilder, stripComment: Boolean) {
if (children.isEmpty)
return
- else if (children forall { y => y.isInstanceOf[Atom[Any]] && !y.isInstanceOf[Text] }) { // add space
+ else if (children forall {
+ case y: Atom[_] => !y.isInstanceOf[Text]
+ case _ => false
+ }) { // add space
val it = children.elements
val f = it.next
toXML(f, f.scope, sb, stripComment)