scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

SortedSet/SortedMap 'to' method behaves incorrectly for the ordering that has nontrivial 'equiv' #4930

Closed scabug closed 13 years ago

scabug commented 13 years ago

Essentially 'to' method in Sorted does not work for the case when '==' doesn't agree with the ordering provided. The source of the problem I believe is Sorted.scala:77 where '==' is examined rather than ordering equiv. The following session demonstrates the problem:

bash-4.1$ scala
Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) Client VM, Java 1.6.0_19).
Type in expressions to have them evaluated.
Type :help for more information.

scala> implicit val ord: Ordering[Array[Byte]] = Ordering.by((_: Array[Byte]).toIterable)
ord: Ordering[Array[Byte]] = scala.math.Ordering$$anon$7@fa8ba9

scala> import collection.immutable.SortedMap
import collection.immutable.SortedMap

scala> val m = SortedMap(Array[Byte](1) -> 0)
m: scala.collection.immutable.SortedMap[Array[Byte],Int] = Map([B@1010435 -> 0)

scala> m.to(Array[Byte](1))
res0: scala.collection.immutable.SortedMap[Array[Byte],Int] = Map()

'from' method works as expected though:

scala> m.from(Array[Byte](1))
res1: scala.collection.immutable.SortedMap[Array[Byte],Int] = Map([B@1010435 -> 0)
scabug commented 13 years ago

Imported From: https://issues.scala-lang.org/browse/SI-4930?orig=1 Reporter: @vigdorchik Affected Versions: 2.9.0-1

scabug commented 13 years ago

Commit Message Bot (anonymous) said: (extempore in r25574) Fixed bug in Sorted "to" not using the ordering. Closes #4930, no review.