|  | 
| 12 | 12 | 
 | 
| 13 | 13 | package scala.collection.compat | 
| 14 | 14 | 
 | 
|  | 15 | +import scala.annotation.nowarn | 
| 15 | 16 | import scala.collection.generic._ | 
| 16 | 17 | import scala.reflect.ClassTag | 
| 17 | 18 | import scala.collection.{ | 
| 18 |  | -  BitSet, | 
| 19 | 19 |   GenTraversable, | 
| 20 | 20 |   IterableLike, | 
| 21 | 21 |   IterableView, | 
| @@ -61,39 +61,129 @@ private[compat] trait PackageShared { | 
| 61 | 61 |        must be non-strict | 
| 62 | 62 |      */ | 
| 63 | 63 |     def builder: m.Builder[A, CC[A]] = fact match { | 
| 64 |  | -      case c.Seq | i.Seq => new IdentityPreservingBuilder[A, i.Seq](i.Seq.newBuilder[A]) | 
|  | 64 | +      case c.Seq | i.Seq => | 
|  | 65 | +        new IdentityPreservingBuilder[A, i.Seq](i.Seq.newBuilder[A]) | 
|  | 66 | + | 
| 65 | 67 |       case c.LinearSeq | i.LinearSeq => | 
| 66 | 68 |         new IdentityPreservingBuilder[A, i.LinearSeq](i.LinearSeq.newBuilder[A]) | 
|  | 69 | +      case i.Queue => | 
|  | 70 | +        new IdentityPreservingBuilder[A, i.Queue](i.Queue.newBuilder[A]) | 
|  | 71 | +      case i.Stream => | 
|  | 72 | +        new IdentityPreservingBuilder[A, i.Stream](i.Stream.newBuilder[A]) | 
|  | 73 | +      case i.Stack => | 
|  | 74 | +        new IdentityPreservingBuilder[A, i.Stack](i.Stack.newBuilder[A]): @nowarn("cat=deprecation") | 
|  | 75 | +      case i.List => | 
|  | 76 | +        new IdentityPreservingBuilder[A, i.List](i.List.newBuilder[A]) | 
|  | 77 | + | 
|  | 78 | +      case c.IndexedSeq | i.IndexedSeq => | 
|  | 79 | +        new IdentityPreservingBuilder[A, i.IndexedSeq](i.IndexedSeq.newBuilder[A]) | 
|  | 80 | +      case i.Vector => | 
|  | 81 | +        new IdentityPreservingBuilder[A, i.Vector](i.Vector.newBuilder[A]) | 
|  | 82 | + | 
|  | 83 | +      case c.Set | i.Set => | 
|  | 84 | +        new IdentityPreservingBuilder[A, i.Set](i.Set.newBuilder[A]) | 
|  | 85 | + | 
|  | 86 | +      case i.HashSet => | 
|  | 87 | +        new IdentityPreservingBuilder[A, i.HashSet](i.HashSet.newBuilder[A]) | 
|  | 88 | +      case i.ListSet => | 
|  | 89 | +        new IdentityPreservingBuilder[A, i.ListSet](i.ListSet.newBuilder[A]) | 
|  | 90 | + | 
|  | 91 | +      case c.Iterable | i.Iterable => | 
|  | 92 | +        new IdentityPreservingBuilder[A, i.Iterable](i.Iterable.newBuilder[A]) | 
|  | 93 | + | 
|  | 94 | +      case c.Traversable | i.Traversable => | 
|  | 95 | +        new IdentityPreservingBuilder[A, i.Traversable](i.Traversable.newBuilder[A]) | 
|  | 96 | + | 
| 67 | 97 |       case _ => fact.newBuilder[A] | 
| 68 | 98 |     } | 
| 69 | 99 |     simpleCBF(builder) | 
| 70 | 100 |   } | 
| 71 | 101 | 
 | 
| 72 | 102 |   implicit def sortedSetCompanionToCBF[A: Ordering, | 
| 73 | 103 |                                        CC[X] <: c.SortedSet[X] with c.SortedSetLike[X, CC[X]]]( | 
| 74 |  | -      fact: SortedSetFactory[CC]): CanBuildFrom[Any, A, CC[A]] = | 
| 75 |  | -    simpleCBF(fact.newBuilder[A]) | 
|  | 104 | +      fact: SortedSetFactory[CC]): CanBuildFrom[Any, A, CC[A]] = { | 
|  | 105 | +    def builder: m.Builder[A, CC[A]] = { | 
|  | 106 | +      val b = fact match { | 
|  | 107 | +        case c.SortedSet | i.SortedSet => | 
|  | 108 | +          new IdentityPreservingBuilder[A, i.SortedSet](i.SortedSet.newBuilder[A]) | 
|  | 109 | +        case i.TreeSet => | 
|  | 110 | +          new IdentityPreservingBuilder[A, i.TreeSet](i.TreeSet.newBuilder[A]) | 
|  | 111 | +        case _ => | 
|  | 112 | +          fact.newBuilder[A] | 
|  | 113 | +      } | 
|  | 114 | +      // Cast needed because GADT inference doesn't unify CC (didn't dig down why). Example: | 
|  | 115 | +      //   def t: CC[A] = fact match { case i.SortedSet => null: i.SortedSet[A] } | 
|  | 116 | +      b.asInstanceOf[m.Builder[A, CC[A]]] | 
|  | 117 | +    } | 
|  | 118 | +    simpleCBF(builder) | 
|  | 119 | +  } | 
| 76 | 120 | 
 | 
| 77 | 121 |   implicit def arrayCompanionToCBF[A: ClassTag](fact: Array.type): CanBuildFrom[Any, A, Array[A]] = | 
| 78 | 122 |     simpleCBF(Array.newBuilder[A]) | 
| 79 | 123 | 
 | 
| 80 |  | -  implicit def mapFactoryToCBF[K, V, CC[A, B] <: Map[A, B] with MapLike[A, B, CC[A, B]]]( | 
| 81 |  | -      fact: MapFactory[CC]): CanBuildFrom[Any, (K, V), CC[K, V]] = | 
| 82 |  | -    simpleCBF(fact.newBuilder[K, V]) | 
|  | 124 | +  // bounds should be `c.` but binary compatibility | 
|  | 125 | +  implicit def mapFactoryToCBF[K, | 
|  | 126 | +                               V, | 
|  | 127 | +                               CC[A, B] <: /*c.*/ Map[A, B] with /*c.*/ MapLike[A, B, CC[A, B]]]( | 
|  | 128 | +      fact: MapFactory[CC]): CanBuildFrom[Any, (K, V), CC[K, V]] = { | 
|  | 129 | +    def builder: m.Builder[(K, V), CC[K, V]] = { | 
|  | 130 | +      val b = fact match { | 
|  | 131 | +        case c.Map | i.Map => | 
|  | 132 | +          new IdentityPreservingMapBuilder[K, V, i.Map](i.Map.newBuilder[K, V]) | 
|  | 133 | +        case i.HashMap => | 
|  | 134 | +          new IdentityPreservingMapBuilder[K, V, i.HashMap](i.HashMap.newBuilder[K, V]) | 
|  | 135 | +        case i.ListMap => | 
|  | 136 | +          new IdentityPreservingMapBuilder[K, V, i.ListMap](i.ListMap.newBuilder[K, V]) | 
|  | 137 | +        case _ => | 
|  | 138 | +          fact.newBuilder[K, V] | 
|  | 139 | +      } | 
|  | 140 | +      // Cast needed because GADT inference doesn't unify CC (didn't dig down why). Example: | 
|  | 141 | +      //   def t: CC[K, V] = fact match { case i.Map => null: i.Map[K, V] } | 
|  | 142 | +      b.asInstanceOf[m.Builder[(K, V), CC[K, V]]] | 
|  | 143 | +    } | 
|  | 144 | +    simpleCBF(builder) | 
|  | 145 | +  } | 
| 83 | 146 | 
 | 
| 84 | 147 |   implicit def sortedMapFactoryToCBF[ | 
| 85 | 148 |       K: Ordering, | 
| 86 | 149 |       V, | 
| 87 | 150 |       CC[A, B] <: c.SortedMap[A, B] with c.SortedMapLike[A, B, CC[A, B]]]( | 
| 88 |  | -      fact: SortedMapFactory[CC]): CanBuildFrom[Any, (K, V), CC[K, V]] = | 
| 89 |  | -    simpleCBF(fact.newBuilder[K, V]) | 
|  | 151 | +      fact: SortedMapFactory[CC]): CanBuildFrom[Any, (K, V), CC[K, V]] = { | 
|  | 152 | +    def builder: m.Builder[(K, V), CC[K, V]] = { | 
|  | 153 | +      val b = fact match { | 
|  | 154 | +        case c.SortedMap | i.SortedMap => | 
|  | 155 | +          new IdentityPreservingMapBuilder[K, V, i.SortedMap](i.SortedMap.newBuilder[K, V]) | 
|  | 156 | +        case i.TreeMap => | 
|  | 157 | +          new IdentityPreservingMapBuilder[K, V, i.TreeMap](i.TreeMap.newBuilder[K, V]) | 
|  | 158 | +        case _ => | 
|  | 159 | +          fact.newBuilder[K, V] | 
|  | 160 | +      } | 
|  | 161 | +      b.asInstanceOf[m.Builder[(K, V), CC[K, V]]] | 
|  | 162 | +    } | 
|  | 163 | +    simpleCBF(builder) | 
|  | 164 | +  } | 
| 90 | 165 | 
 | 
| 91 |  | -  implicit def bitSetFactoryToCBF(fact: BitSetFactory[BitSet]): CanBuildFrom[Any, Int, BitSet] = | 
| 92 |  | -    simpleCBF(fact.newBuilder) | 
|  | 166 | +  implicit def bitSetFactoryToCBF( | 
|  | 167 | +      fact: BitSetFactory[c.BitSet]): CanBuildFrom[Any, Int, c.BitSet] = { | 
|  | 168 | +    def builder: m.Builder[Int, c.BitSet] = fact match { | 
|  | 169 | +      case c.BitSet => | 
|  | 170 | +        new IdentityPreservingBitSetBuilder[i.BitSet](i.BitSet.newBuilder) | 
|  | 171 | +      case _ => | 
|  | 172 | +        fact.newBuilder | 
|  | 173 | +    } | 
|  | 174 | +    simpleCBF(builder) | 
|  | 175 | +  } | 
| 93 | 176 | 
 | 
| 94 | 177 |   implicit def immutableBitSetFactoryToCBF( | 
| 95 |  | -      fact: BitSetFactory[i.BitSet]): CanBuildFrom[Any, Int, ImmutableBitSetCC[Int]] = | 
| 96 |  | -    simpleCBF(fact.newBuilder) | 
|  | 178 | +      fact: BitSetFactory[i.BitSet]): CanBuildFrom[Any, Int, ImmutableBitSetCC[Int]] = { | 
|  | 179 | +    def builder: m.Builder[Int, i.BitSet] = fact match { | 
|  | 180 | +      case i.BitSet => | 
|  | 181 | +        new IdentityPreservingBitSetBuilder[i.BitSet](i.BitSet.newBuilder) | 
|  | 182 | +      case _ => | 
|  | 183 | +        fact.newBuilder | 
|  | 184 | +    } | 
|  | 185 | +    simpleCBF(builder) | 
|  | 186 | +  } | 
| 97 | 187 | 
 | 
| 98 | 188 |   implicit def mutableBitSetFactoryToCBF( | 
| 99 | 189 |       fact: BitSetFactory[m.BitSet]): CanBuildFrom[Any, Int, MutableBitSetCC[Int]] = | 
|  | 
0 commit comments