Skip to content

Commit e5cf68d

Browse files
committed
Fix TreeMap class hierarchy
Inherit `StrictOptimizedMapOps` to refine return type of map, flatmap, concat and collect. See scala/scala3#4839
1 parent 58f6e22 commit e5cf68d

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/library/scala/collection/immutable/TreeMap.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ final class TreeMap[K, +V] private (tree: RB.Tree[K, V])(implicit val ordering:
3030
with SortedMap[K, V]
3131
with SortedMapOps[K, V, TreeMap, TreeMap[K, V]]
3232
with StrictOptimizedIterableOps[(K, V), Iterable, TreeMap[K, V]]
33+
with StrictOptimizedMapOps[K, V, Map, TreeMap[K, V]]
3334
with StrictOptimizedSortedMapOps[K, V, TreeMap, TreeMap[K, V]] {
3435

3536
def this()(implicit ordering: Ordering[K]) = this(null)(ordering)
3637

3738
override def sortedMapFactory = TreeMap
3839

39-
def iterator: collection.Iterator[(K, V)] = RB.iterator(tree)
40+
def iterator: Iterator[(K, V)] = RB.iterator(tree)
4041

41-
def keysIteratorFrom(start: K): collection.Iterator[K] = RB.keysIterator(tree, Some(start))
42+
def keysIteratorFrom(start: K): Iterator[K] = RB.keysIterator(tree, Some(start))
4243

4344
def iteratorFrom(start: K): Iterator[(K, V)] = RB.iterator(tree, Some(start))
4445

@@ -152,7 +153,7 @@ object TreeMap extends SortedMapFactory[TreeMap] {
152153

153154
def empty[K : Ordering, V]: TreeMap[K, V] = new TreeMap()
154155

155-
def from[K : Ordering, V](it: collection.IterableOnce[(K, V)]): TreeMap[K, V] =
156+
def from[K : Ordering, V](it: IterableOnce[(K, V)]): TreeMap[K, V] =
156157
it match {
157158
case tm: TreeMap[K, V] => tm
158159
case _ => (newBuilder[K, V] ++= it).result()

src/library/scala/collection/mutable/TreeMap.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package scala
2-
package collection.mutable
2+
package collection
3+
package mutable
34

4-
import collection.{Iterator, SortedMapFactory, StrictOptimizedIterableOps, StrictOptimizedSortedMapOps}
55
import collection.mutable.{RedBlackTree => RB}
6-
import java.lang.String
76

87
/**
98
* A mutable sorted map implemented using a mutable red-black tree as underlying data structure.
@@ -23,6 +22,7 @@ sealed class TreeMap[K, V] private (tree: RB.Tree[K, V])(implicit val ordering:
2322
with SortedMap[K, V]
2423
with SortedMapOps[K, V, TreeMap, TreeMap[K, V]]
2524
with StrictOptimizedIterableOps[(K, V), Iterable, TreeMap[K, V]]
25+
with StrictOptimizedMapOps[K, V, Map, TreeMap[K, V]]
2626
with StrictOptimizedSortedMapOps[K, V, TreeMap, TreeMap[K, V]] {
2727

2828
override def sortedMapFactory = TreeMap
@@ -178,7 +178,7 @@ sealed class TreeMap[K, V] private (tree: RB.Tree[K, V])(implicit val ordering:
178178
@SerialVersionUID(3L)
179179
object TreeMap extends SortedMapFactory[TreeMap] {
180180

181-
def from[K : Ordering, V](it: collection.IterableOnce[(K, V)]): TreeMap[K, V] =
181+
def from[K : Ordering, V](it: IterableOnce[(K, V)]): TreeMap[K, V] =
182182
Growable.from(empty[K, V], it)
183183

184184
def empty[K : Ordering, V]: TreeMap[K, V] = new TreeMap[K, V]()

0 commit comments

Comments
 (0)