Skip to content

Commit 4094ebe

Browse files
committed
Cross-build
1 parent 7dbb249 commit 4094ebe

13 files changed

+66
-69
lines changed

build.sbt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ThisBuild / scalaVersion := "3.3.3"
1+
ThisBuild / scalaVersion := "3.4.1"
22
ThisBuild / crossScalaVersions := Seq((ThisBuild / scalaVersion).value, "2.13.13")
33

44
lazy val root = project.in(file("."))
@@ -20,8 +20,15 @@ lazy val collectionContrib = crossProject(JVMPlatform, JSPlatform, NativePlatfor
2020
scalaModuleAutomaticModuleName := Some("scala.collection.contrib"),
2121
Compile / compile / scalacOptions ++= {
2222
CrossVersion.partialVersion(scalaVersion.value) match {
23-
case Some((2, _)) => Seq("-opt-warnings", "-Werror", "-Wconf:origin=scala.collection.IterableOps.toIterable:s")
24-
case _ => Seq("-Xfatal-warnings", "-Wconf:cat=deprecation:s")
23+
case Some((2, _)) => Seq(
24+
"-Werror", "-Wconf:origin=scala.collection.IterableOps.toIterable:s",
25+
"-Wopt", "-opt:inline:<sources>",
26+
"-Wnonunit-statement",
27+
"-Wvalue-discard",
28+
"-Xlint",
29+
"-Xsource:3-cross",
30+
)
31+
case _ => Seq("-Werror", "-Wconf:cat=deprecation:s")
2532
}
2633
},
2734
Compile / doc / scalacOptions ++= {

src/main/scala/scala/collection/MultiDict.scala

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trait MultiDict[K, V]
1313
with MultiDictOps[K, V, MultiDict, MultiDict[K, V]]
1414
with Equals {
1515

16-
override protected[this] def className: String = "MultiDict"
16+
override protected def className: String = "MultiDict"
1717

1818
def multiDictFactory: MapFactory[MultiDict] = MultiDict
1919
override protected def fromSpecific(coll: IterableOnce[(K, V)]): MultiDict[K, V] = multiDictFactory.from(coll)
@@ -26,14 +26,12 @@ trait MultiDict[K, V]
2626
override def equals(o: Any): Boolean = o match {
2727
case that: MultiDict[K @unchecked, _] =>
2828
(this eq that) ||
29-
(that canEqual this) &&
30-
(this.size == that.size) && {
31-
try {
32-
sets forall { case (k, vs) => that.sets.get(k).contains(vs) }
33-
} catch {
29+
that.canEqual(this) &&
30+
this.size == that.size && {
31+
try sets.forall { case (k, vs) => that.sets.get(k).contains(vs) }
32+
catch {
3433
case _: ClassCastException => false
35-
}
36-
}
34+
}}
3735
case _ => false
3836
}
3937

@@ -205,7 +203,7 @@ trait MultiDictOps[K, V, +CC[X, Y] <: MultiDict[X, Y], +C <: MultiDict[K, V]]
205203
object MultiDictOps {
206204

207205
class WithFilter[K, V, +IterableCC[_], +CC[X, Y] <: MultiDict[X, Y]](
208-
`this`: MultiDictOps[K, V, CC, _] with IterableOps[(K, V), IterableCC, _],
206+
`this`: MultiDictOps[K, V, CC, ?] & IterableOps[(K, V), IterableCC, ?],
209207
p: ((K, V)) => Boolean
210208
) extends IterableOps.WithFilter[(K, V), IterableCC](`this`, p) {
211209

src/main/scala/scala/collection/MultiSet.scala

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait MultiSet[A]
1212
with MultiSetOps[A, MultiSet, MultiSet[A]]
1313
with Equals {
1414

15-
override protected[this] def className: String = "MultiSet"
15+
override protected def className: String = "MultiSet"
1616

1717
override def iterableFactory: IterableFactory[MultiSet] = MultiSet
1818
override protected def fromSpecific(coll: IterableOnce[A]): MultiSet[A] = iterableFactory.from(coll)
@@ -24,14 +24,12 @@ trait MultiSet[A]
2424
override def equals(o: Any): Boolean = o match {
2525
case that: MultiSet[A @unchecked] =>
2626
(this eq that) ||
27-
(that canEqual this) &&
28-
(this.size == that.size) && {
29-
try {
30-
occurrences forall { case (elem, n) => that.get(elem) == n }
31-
} catch {
27+
that.canEqual(this) &&
28+
this.size == that.size && {
29+
try occurrences.forall { case (elem, n) => that.get(elem) == n }
30+
catch {
3231
case _: ClassCastException => false
33-
}
34-
}
32+
}}
3533
case _ => false
3634
}
3735

@@ -42,10 +40,10 @@ trait MultiSet[A]
4240
trait MultiSetOps[A, +CC[X] <: MultiSet[X], +C <: MultiSet[A]]
4341
extends IterableOps[A, CC, C] {
4442

45-
protected[this] def fromSpecificOccurrences(it: Iterable[(A, Int)]): C =
43+
protected def fromSpecificOccurrences(it: Iterable[(A, Int)]): C =
4644
fromSpecific(it.view.flatMap { case (e, n) => new View.Fill(n)(e) })
4745

48-
protected[this] def fromOccurrences[E](it: Iterable[(E, Int)]): CC[E] =
46+
protected def fromOccurrences[E](it: Iterable[(E, Int)]): CC[E] =
4947
// Note new MultiSet(it.to(Map)) would be more efficient but would also loose duplicates
5048
iterableFactory.from(it.view.flatMap { case (e, n) => new View.Fill(n)(e) })
5149

src/main/scala/scala/collection/SortedMultiDict.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ trait SortedMultiDictOps[K, V, +CC[X, Y] <: MultiDict[X, Y], +C <: MultiDict[K,
2525

2626
def sortedMultiDictFactory: SortedMapFactory[CC]
2727

28-
protected[this] def sortedFromIterable[L : Ordering, W](it: Iterable[(L, W)]): CC[L, W] = sortedMultiDictFactory.from(it)
29-
protected[this] def sortedFromSets[L : Ordering, W](it: Iterable[(L, Set[W])]): CC[L, W] =
28+
protected def sortedFromIterable[L : Ordering, W](it: Iterable[(L, W)]): CC[L, W] = sortedMultiDictFactory.from(it)
29+
protected def sortedFromSets[L : Ordering, W](it: Iterable[(L, Set[W])]): CC[L, W] =
3030
sortedFromIterable(it.view.flatMap { case (l, ws) => ws.map(w => (l, w)) })
3131

3232
/** `this` sorted multidict upcasted to an unsorted multidict */
@@ -126,7 +126,7 @@ trait SortedMultiDictOps[K, V, +CC[X, Y] <: MultiDict[X, Y], +C <: MultiDict[K,
126126
object SortedMultiDictOps {
127127

128128
class WithFilter[K, V, +IterableCC[_], +MultiDictCC[X, Y] <: MultiDict[X, Y], +CC[X, Y] <: MultiDict[X, Y]](
129-
`this`: SortedMultiDictOps[K, V, CC, _] with MultiDictOps[K, V, MultiDictCC, _] with IterableOps[(K, V), IterableCC, _],
129+
`this`: SortedMultiDictOps[K, V, CC, ?] & MultiDictOps[K, V, MultiDictCC, ?] & IterableOps[(K, V), IterableCC, ?],
130130
p: ((K, V)) => Boolean
131131
) extends MultiDictOps.WithFilter[K, V, IterableCC, MultiDictCC](`this`, p) {
132132

src/main/scala/scala/collection/SortedMultiSet.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ trait SortedMultiSetOps[A, +CC[X] <: MultiSet[X], +C <: MultiSet[A]]
118118
* is the minimum of the lengths of `this` and `that`
119119
*/
120120
def zip[B](that: Iterable[B])(implicit ev: Ordering[B]): CC[(A @uncheckedVariance, B)] = // sound bcs of VarianceNote
121-
sortedFromIterable(new View.Zip(toIterable, that))(Ordering.Tuple2(ordering, implicitly))
121+
sortedFromIterable(new View.Zip(toIterable, that))(using Ordering.Tuple2(ordering, implicitly))
122122

123123
/**
124124
* @return a new collection resulting from applying the given partial
@@ -147,7 +147,7 @@ trait SortedMultiSetOps[A, +CC[X] <: MultiSet[X], +C <: MultiSet[A]]
147147
// --- Override return type of methods that returned an unsorted MultiSet
148148

149149
override def zipWithIndex: CC[(A, Int)] =
150-
sortedFromIterable(new View.ZipWithIndex(toIterable))(Ordering.Tuple2(ordering, implicitly))
150+
sortedFromIterable(new View.ZipWithIndex(toIterable))(using Ordering.Tuple2(ordering, implicitly))
151151

152152
}
153153

@@ -158,7 +158,7 @@ object SortedMultiSetOps {
158158
* @define coll sorted collection
159159
*/
160160
class WithFilter[A, +IterableCC[_], +CC[X] <: MultiSet[X]](
161-
`this`: SortedMultiSetOps[A, CC, _] with IterableOps[A, IterableCC, _],
161+
`this`: SortedMultiSetOps[A, CC, ?] & IterableOps[A, IterableCC, ?],
162162
p: A => Boolean
163163
) extends IterableOps.WithFilter[A, IterableCC](`this`, p) {
164164

src/main/scala/scala/collection/decorators/BitSetDecorator.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package scala.collection.decorators
22

33
import scala.collection.{BitSet, BitSetOps}
44

5-
class BitSetDecorator[+C <: BitSet with BitSetOps[C]](protected val bs: C) {
5+
class BitSetDecorator[+C <: BitSet & BitSetOps[C]](protected val bs: C) {
66

77
import BitSetDecorator._
88
import BitSetOps._

src/main/scala/scala/collection/decorators/IteratorDecorator.scala

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package scala.collection
22
package decorators
33

44
import scala.annotation.tailrec
5+
import scala.util.chaining._
56
import scala.util.control.NonFatal
67

78
/** Enriches Iterator with additional methods.
@@ -188,8 +189,8 @@ class IteratorDecorator[A](val `this`: Iterator[A]) extends AnyVal {
188189
*/
189190
def splitBy[K](f: A => K): Iterator[immutable.Seq[A]] =
190191
new AbstractIterator[immutable.Seq[A]] {
191-
private var hd: A = _
192-
private var hdKey: K = _
192+
private var hd: A = null.asInstanceOf[A] // todo uninitialized
193+
private var hdKey: K = null.asInstanceOf[K] // todo uninitialized
193194
private var hdDefined: Boolean = false
194195

195196
override def hasNext: Boolean = hdDefined || `this`.hasNext
@@ -240,32 +241,26 @@ class IteratorDecorator[A](val `this`: Iterator[A]) extends AnyVal {
240241
}
241242

242243
/** Gives elements from the source iterator until the source iterator ends or throws a NonFatal exception.
243-
*
244-
* @param exceptionCaught a callback invoked from `hasNext` when the source iterator throws a NonFatal exception
245-
* @return an iterator that takes items until the wrapped iterator ends or throws a NonFatal exception
246-
* @see scala.util.control.NonFatal
247-
* @note Reuse: $consumesAndProducesIterator
248-
*/
249-
def takeUntilException(exceptionCaught: Throwable => Unit): Iterator[A] = {
244+
*
245+
* @param exceptionCaught a callback invoked from `hasNext` when the source iterator throws a NonFatal exception
246+
* @return an iterator that takes items until the wrapped iterator ends or throws a NonFatal exception
247+
* @see scala.util.control.NonFatal
248+
* @note Reuse: $consumesAndProducesIterator
249+
*/
250+
def takeUntilException(exceptionCaught: Throwable => Unit): Iterator[A] =
250251
new AbstractIterator[A] {
251252
private val wrapped = `this`.buffered
252253

253-
override def hasNext: Boolean = {
254-
try {
255-
val n = wrapped.hasNext
256-
// By already invoking `head` (and therefore also `next` on `this`),
257-
// we are sure that `wrapped.next` will not throw when it is used from
258-
// `next`.
259-
if (n) wrapped.head
260-
n
261-
} catch {
254+
override def hasNext: Boolean =
255+
// By already invoking `head` (and therefore also `next` on `this`),
256+
// we are sure that `wrapped.next` will not throw when it is used from `next`.
257+
try wrapped.hasNext.tap(if(_) wrapped.head)
258+
catch {
262259
case NonFatal(t) =>
263260
exceptionCaught(t)
264261
false
265262
}
266-
}
267263

268264
override def next(): A = wrapped.next()
269265
}
270-
}
271266
}

src/main/scala/scala/collection/decorators/package.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package object decorators {
1717
implicit def mapDecorator[C](coll: C)(implicit map: IsMap[C]): MapDecorator[C, map.type] =
1818
new MapDecorator(coll)(map)
1919

20-
implicit def bitSetDecorator[C <: BitSet with BitSetOps[C]](bs: C): BitSetDecorator[C] =
20+
implicit def bitSetDecorator[C <: BitSet & BitSetOps[C]](bs: C): BitSetDecorator[C] =
2121
new BitSetDecorator(bs)
2222

2323
implicit def mutableBitSetDecorator(bs: mutable.BitSet): MutableBitSetDecorator =

src/main/scala/scala/collection/decorators/views.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package decorators
44
/** Views used by decorators */
55
object View {
66

7-
type SomeIterableOps[+A] = IterableOps[A, AnyConstr, _]
7+
type SomeIterableOps[+A] = IterableOps[A, AnyConstr, ?]
88

99
class Intersperse[A](underlying: SomeIterableOps[A], sep: A) extends View[A] {
1010
def iterator: Iterator[A] = underlying.iterator.intersperse(sep)
@@ -21,4 +21,4 @@ object View {
2121
else underlying.knownSize
2222
}
2323

24-
}
24+
}

src/main/scala/scala/collection/mutable/MultiDict.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ package scala
22
package collection
33
package mutable
44

5-
/**
6-
* A mutable multidict
7-
* @tparam K the type of keys
8-
* @tparam V the type of values
9-
*/
5+
/** A mutable multidict.
6+
* @tparam K the type of keys
7+
* @tparam V the type of values
8+
*/
109
class MultiDict[K, V] private (elems: Map[K, Set[V]])
1110
extends collection.MultiDict[K, V]
1211
with Iterable[(K, V)]
@@ -27,7 +26,7 @@ class MultiDict[K, V] private (elems: Map[K, Set[V]])
2726

2827
def addOne(elem: (K, V)): this.type = {
2928
val (k, v) = elem
30-
elems.updateWith(k) {
29+
val _ = elems.updateWith(k) {
3130
case None => Some(Set(v))
3231
case Some(vs) => Some(vs += v)
3332
}
@@ -36,7 +35,7 @@ class MultiDict[K, V] private (elems: Map[K, Set[V]])
3635

3736
def subtractOne(elem: (K, V)): this.type = {
3837
val (k, v) = elem
39-
elems.updateWith(k) {
38+
val _ = elems.updateWith(k) {
4039
case Some(vs) =>
4140
vs -= v
4241
if (vs.nonEmpty) Some(vs) else None
@@ -69,4 +68,4 @@ object MultiDict extends MapFactory[MultiDict] {
6968

7069
def newBuilder[K, V]: Builder[(K, V), MultiDict[K, V]] = new GrowableBuilder[(K, V), MultiDict[K, V]](empty)
7170

72-
}
71+
}

0 commit comments

Comments
 (0)