From 1ca873460442a7b80864ef02e49f96116898bf44 Mon Sep 17 00:00:00 2001 From: extempore Date: Sat, 27 Aug 2011 18:01:40 +0000 Subject: [PATCH] Fixed bug in Sorted "to" not using the ordering. Closes SI-4930, no review. git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@25574 5e8d7ff9-d8ef-0310-90f0-a4852d11357a --- src/library/scala/collection/generic/Sorted.scala | 3 +-- test/files/run/t4930.check | 2 ++ test/files/run/t4930.scala | 11 +++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 test/files/run/t4930.check create mode 100644 test/files/run/t4930.scala diff --git a/src/library/scala/collection/generic/Sorted.scala b/src/library/scala/collection/generic/Sorted.scala index c7ad92cc6..2dc2891e4 100644 --- a/src/library/scala/collection/generic/Sorted.scala +++ b/src/library/scala/collection/generic/Sorted.scala @@ -71,11 +71,10 @@ trait Sorted[K, +This <: Sorted[K, This]] { * @param to The upper-bound (inclusive) of the ranged projection. */ def to(to: K): This = { - // tough! val i = keySet.from(to).iterator if (i.isEmpty) return repr val next = i.next - if (next == to) + if (compare(next, to) == 0) if (i.isEmpty) repr else until(i.next) else diff --git a/test/files/run/t4930.check b/test/files/run/t4930.check new file mode 100644 index 000000000..a58efd468 --- /dev/null +++ b/test/files/run/t4930.check @@ -0,0 +1,2 @@ +List(1) +List(1) diff --git a/test/files/run/t4930.scala b/test/files/run/t4930.scala new file mode 100644 index 000000000..775f62794 --- /dev/null +++ b/test/files/run/t4930.scala @@ -0,0 +1,11 @@ +import collection.immutable.SortedMap + +object Test { + implicit val ord: Ordering[Array[Byte]] = Ordering.by((_: Array[Byte]).toIterable) + + def main(args: Array[String]): Unit = { + val m = SortedMap(Array[Byte](1) -> 0) + println(m.to(Array[Byte](1)) flatMap (_._1.mkString)) + println(m.from(Array[Byte](1)) flatMap (_._1.mkString)) + } +}