This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Seq.indexOf overload

No replies
Jesper Nordenberg
Joined: 2008-12-27,
User offline. Last seen 42 years 45 weeks ago.

Seq.indexOf is overloaded in two method with different functionality.
This causes problems when you put a Seq inside another Seq, for example:

scala> val l = List(1, 2, 3)
l: List[Int] = List(1, 2, 3)

scala> List(l).indexOf(l)
res4: Int = -1

Apparently the "indexOf[B >: A](that : Seq[B])" method is chosen by the
compiler. I saw that the same overload is present in scalax. I don't
know if there are other methods in the collections library that are
overloaded in the same way.

The obvious solution is to rename "indexOf[B >: A](that : Seq[B])" to
indexOfSeq, indexOfSlice or similar.

/Jesper Nordenberg

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland