diff --git a/.scalafmt.conf b/.scalafmt.conf index d4306c2c25..d15fc0abb9 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -8,6 +8,12 @@ project.excludeFilters = [ "scalafix/*" ] +fileOverride { + "glob:**/scala-3/**" { + runner.dialect = scala3 + } +} + docstrings.wrap = "no" maxColumn = 100 diff --git a/benchmark/src/main/scala/fs2/benchmark/ChannelBenchmark.scala b/benchmark/src/main/scala/fs2/benchmark/ChannelBenchmark.scala index 89cc2efd06..8a7af91bdf 100644 --- a/benchmark/src/main/scala/fs2/benchmark/ChannelBenchmark.scala +++ b/benchmark/src/main/scala/fs2/benchmark/ChannelBenchmark.scala @@ -38,7 +38,7 @@ class ChannelBenchmark { var lists: List[List[Unit]] = _ @Setup - def setup() { + def setup() = { list = List.fill(size)(()) val subList = List.fill(size / 8)(()) lists = List.fill(8)(subList) @@ -70,7 +70,7 @@ class ChannelBenchmark { .bounded[IO, Unit](size / 8) .flatMap { channel => val action = sendAll(list, channel.send(()).start.void) - action *> channel.stream.take(size).through(blackHole).compile.drain + action *> channel.stream.take(size.toLong).through(blackHole).compile.drain } .unsafeRunSync() diff --git a/build.sbt b/build.sbt index 94963ce462..a16dc3e126 100644 --- a/build.sbt +++ b/build.sbt @@ -6,8 +6,6 @@ addCommandAlias( "fmtCheck", "; Compile/scalafmtCheck; Test/scalafmtCheck; IntegrationTest/scalafmtCheck; scalafmtSbtCheck" ) -addCommandAlias("testJVM", ";rootJVM/test") -addCommandAlias("testJS", "rootJS/test") Global / onChangedBuildSource := ReloadOnSourceChanges Global / stQuiet := true @@ -65,15 +63,9 @@ ThisBuild / developers ++= List( Developer(username, fullName, s"@$username", url(s"https://github.com/$username")) } -ThisBuild / fatalWarningsInCI := false - -ThisBuild / Test / javaOptions ++= Seq( - "-Dscala.concurrent.context.minThreads=8", - "-Dscala.concurrent.context.numThreads=8", - "-Dscala.concurrent.context.maxThreads=8" -) -ThisBuild / Test / run / javaOptions ++= Seq("-Xms64m", "-Xmx64m") -ThisBuild / Test / parallelExecution := false +// If debugging tests, it's sometimes useful to disable parallel execution and test result buffering: +// ThisBuild / Test / parallelExecution := false +// ThisBuild / Test / testOptions += Tests.Argument(TestFrameworks.MUnit, "-b") ThisBuild / initialCommands := s""" import fs2._, cats.effect._, cats.effect.implicits._, cats.effect.unsafe.implicits.global, cats.syntax.all._, scala.concurrent.duration._ @@ -169,7 +161,8 @@ ThisBuild / mimaBinaryIssueFilters ++= Seq( ProblemFilters.exclude[MissingClassProblem]( "fs2.io.net.SocketCompanionPlatform$IntCallbackHandler" ), - ProblemFilters.exclude[MissingClassProblem]("fs2.Chunk$BufferChunk") + ProblemFilters.exclude[MissingClassProblem]("fs2.Chunk$BufferChunk"), + ProblemFilters.exclude[DirectMissingMethodProblem]("fs2.Chunk.makeArrayBuilder") ) lazy val root = project @@ -203,11 +196,9 @@ lazy val core = crossProject(JVMPlatform, JSPlatform) .configs(IntegrationTest) .settings(Defaults.itSettings: _*) .settings( - inConfig(IntegrationTest)( - org.scalafmt.sbt.ScalafmtPlugin.scalafmtConfigSettings ++ List( - Test / javaOptions += "-Dcats.effect.tracing.mode=none" - ) - ) + inConfig(IntegrationTest)(org.scalafmt.sbt.ScalafmtPlugin.scalafmtConfigSettings), + IntegrationTest / fork := true, + IntegrationTest / javaOptions += "-Dcats.effect.tracing.mode=none" ) .settings( name := "fs2-core", @@ -235,16 +226,13 @@ lazy val core = crossProject(JVMPlatform, JSPlatform) ) }, Compile / doc / scalacOptions ++= (if (scalaVersion.value.startsWith("2.")) Seq("-nowarn") - else Nil), - Compile / scalafmt / unmanagedSources := (Compile / scalafmt / unmanagedSources).value - .filterNot(_.toString.endsWith("NotGiven.scala")), - Test / scalafmt / unmanagedSources := (Test / scalafmt / unmanagedSources).value - .filterNot(_.toString.endsWith("NotGiven.scala")) + else Nil) ) lazy val coreJVM = core.jvm .settings( - Test / fork := true + Test / fork := true, + doctestIgnoreRegex := Some(".*NotGiven.scala") ) lazy val coreJS = core.js @@ -332,12 +320,12 @@ lazy val reactiveStreams = project .in(file("reactive-streams")) .settings( name := "fs2-reactive-streams", - Test / fork := true, libraryDependencies ++= Seq( "org.reactivestreams" % "reactive-streams" % "1.0.3", "org.reactivestreams" % "reactive-streams-tck" % "1.0.3" % "test", ("org.scalatestplus" %% "testng-6-7" % "3.2.10.0" % "test").cross(CrossVersion.for3Use2_13) - ) + ), + Test / fork := true // Otherwise SubscriberStabilitySpec fails ) .dependsOn(coreJVM % "compile->compile;test->test") diff --git a/core/shared/src/main/scala-2.12/fs2/ChunkPlatform.scala b/core/shared/src/main/scala-2.12/fs2/ChunkPlatform.scala index b34894ca04..24644073f3 100644 --- a/core/shared/src/main/scala-2.12/fs2/ChunkPlatform.scala +++ b/core/shared/src/main/scala-2.12/fs2/ChunkPlatform.scala @@ -21,7 +21,7 @@ package fs2 -import scala.collection.mutable.{ArrayBuilder, WrappedArray} +import scala.collection.mutable.WrappedArray import scala.reflect.ClassTag private[fs2] trait ChunkPlatform[+O] { self: Chunk[O] => } @@ -34,9 +34,6 @@ private[fs2] trait ChunkCompanionPlatform { self: Chunk.type => case _ => None } - private[fs2] def makeArrayBuilder[A](implicit ct: ClassTag[A]): ArrayBuilder[A] = - ArrayBuilder.make()(ct) - /** Creates a chunk backed by a `WrappedArray` */ def wrappedArray[O](wrappedArray: WrappedArray[O]): Chunk[O] = { diff --git a/core/shared/src/main/scala-2.12/fs2/internal/package.scala b/core/shared/src/main/scala-2.12/fs2/internal/package.scala index 531376bdca..5857809fb7 100644 --- a/core/shared/src/main/scala-2.12/fs2/internal/package.scala +++ b/core/shared/src/main/scala-2.12/fs2/internal/package.scala @@ -22,7 +22,8 @@ package fs2 import scala.collection.generic.CanBuildFrom -import scala.collection.mutable.Builder +import scala.collection.mutable.{ArrayBuilder, Builder} +import scala.reflect.ClassTag package object internal { private[fs2] type Factory[-A, +C] = CanBuildFrom[Nothing, A, C] @@ -30,4 +31,7 @@ package object internal { private[fs2] implicit class FactoryOps[-A, +C](private val factory: Factory[A, C]) { def newBuilder: Builder[A, C] = factory() } + + private[fs2] def makeArrayBuilder[A](implicit ct: ClassTag[A]): ArrayBuilder[A] = + ArrayBuilder.make()(ct) } diff --git a/core/shared/src/main/scala-2.13/fs2/ChunkPlatform.scala b/core/shared/src/main/scala-2.13/fs2/ChunkPlatform.scala index 42fbc895cf..402ae08aed 100644 --- a/core/shared/src/main/scala-2.13/fs2/ChunkPlatform.scala +++ b/core/shared/src/main/scala-2.13/fs2/ChunkPlatform.scala @@ -23,7 +23,6 @@ package fs2 import scala.collection.immutable.ArraySeq import scala.collection.immutable -import scala.collection.mutable.ArrayBuilder import scala.reflect.ClassTag private[fs2] trait ChunkPlatform[+O] { self: Chunk[O] => @@ -54,9 +53,6 @@ private[fs2] trait ChunkCompanionPlatform { self: Chunk.type => case _ => None } - private[fs2] def makeArrayBuilder[A](implicit ct: ClassTag[A]): ArrayBuilder[A] = - ArrayBuilder.make(ct) - /** Creates a chunk backed by an immutable `ArraySeq`. */ def arraySeq[O](arraySeq: immutable.ArraySeq[O]): Chunk[O] = { diff --git a/core/shared/src/main/scala-2.13/internal/package.scala b/core/shared/src/main/scala-2.13/internal/package.scala index 773d8db782..4da7e022db 100644 --- a/core/shared/src/main/scala-2.13/internal/package.scala +++ b/core/shared/src/main/scala-2.13/internal/package.scala @@ -21,6 +21,12 @@ package fs2 +import scala.reflect.ClassTag +import scala.collection.mutable.ArrayBuilder + package object internal { private[fs2] type Factory[-A, +C] = scala.collection.Factory[A, C] + + private[fs2] def makeArrayBuilder[A](implicit ct: ClassTag[A]): ArrayBuilder[A] = + ArrayBuilder.make(ct) } diff --git a/core/shared/src/main/scala-3/fs2/ChunkPlatform.scala b/core/shared/src/main/scala-3/fs2/ChunkPlatform.scala index cef2ca82a1..35c037f3ab 100644 --- a/core/shared/src/main/scala-3/fs2/ChunkPlatform.scala +++ b/core/shared/src/main/scala-3/fs2/ChunkPlatform.scala @@ -23,7 +23,6 @@ package fs2 import scala.collection.immutable.ArraySeq import scala.collection.immutable -import scala.collection.mutable.ArrayBuilder import scala.reflect.ClassTag private[fs2] trait ChunkPlatform[+O] { self: Chunk[O] => @@ -63,9 +62,6 @@ private[fs2] trait ChunkCompanionPlatform { self: Chunk.type => case _ => None } - private[fs2] def makeArrayBuilder[A](implicit ct: ClassTag[A]): ArrayBuilder[A] = - ArrayBuilder.make(ct) - /** Creates a chunk backed by an immutable `ArraySeq`. */ def arraySeq[O](arraySeq: immutable.ArraySeq[O]): Chunk[O] = { @@ -92,8 +88,7 @@ private[fs2] trait ChunkCompanionPlatform { self: Chunk.type => def apply(i: Int) = values(offset + i) def copyToArray[O2 >: O](xs: Array[O2], start: Int): Unit = - if (xs.getClass eq ct.wrap.runtimeClass) - System.arraycopy(values, offset, xs, start, length) + if (xs.getClass eq ct.wrap.runtimeClass) System.arraycopy(values, offset, xs, start, length) else { values.iterator.slice(offset, offset + length).copyToArray(xs, start) () diff --git a/core/shared/src/main/scala-3/fs2/compat/NotGiven.scala b/core/shared/src/main/scala-3/fs2/compat/NotGiven.scala index 12753936c1..1db42eb0a1 100644 --- a/core/shared/src/main/scala-3/fs2/compat/NotGiven.scala +++ b/core/shared/src/main/scala-3/fs2/compat/NotGiven.scala @@ -22,4 +22,4 @@ package fs2.compat type NotGiven[+A] = scala.util.NotGiven[A] -val NotGiven = scala.util.NotGiven \ No newline at end of file +val NotGiven = scala.util.NotGiven diff --git a/core/shared/src/main/scala-3/internal/package.scala b/core/shared/src/main/scala-3/internal/package.scala index 773d8db782..4da7e022db 100644 --- a/core/shared/src/main/scala-3/internal/package.scala +++ b/core/shared/src/main/scala-3/internal/package.scala @@ -21,6 +21,12 @@ package fs2 +import scala.reflect.ClassTag +import scala.collection.mutable.ArrayBuilder + package object internal { private[fs2] type Factory[-A, +C] = scala.collection.Factory[A, C] + + private[fs2] def makeArrayBuilder[A](implicit ct: ClassTag[A]): ArrayBuilder[A] = + ArrayBuilder.make(ct) } diff --git a/core/shared/src/main/scala/fs2/Chunk.scala b/core/shared/src/main/scala/fs2/Chunk.scala index d99c761b0a..e5eea72e39 100644 --- a/core/shared/src/main/scala/fs2/Chunk.scala +++ b/core/shared/src/main/scala/fs2/Chunk.scala @@ -32,6 +32,8 @@ import cats.{Alternative, Applicative, Eq, Eval, Monad, Monoid, Traverse, Traver import cats.data.{Chain, NonEmptyList} import cats.syntax.all._ +import fs2.internal._ + /** Immutable, strict, finite sequence of values that supports efficient index-based random access of elements, * is memory efficient for all sizes, and avoids unnecessary copying. * @@ -80,7 +82,7 @@ abstract class Chunk[+O] extends Serializable with ChunkPlatform[O] with ChunkRu /** More efficient version of `filter(pf.isDefinedAt).map(pf)`. */ def collect[O2](pf: PartialFunction[O, O2]): Chunk[O2] = { - val b = Chunk.makeArrayBuilder[Any] + val b = makeArrayBuilder[Any] b.sizeHint(size) foreach(o => if (pf.isDefinedAt(o)) b += pf(o)) Chunk.array(b.result()).asInstanceOf[Chunk[O2]] @@ -112,7 +114,7 @@ abstract class Chunk[+O] extends Serializable with ChunkPlatform[O] with ChunkRu /** Returns a chunk that has only the elements that satisfy the supplied predicate. */ def filter(p: O => Boolean): Chunk[O] = { - val b = Chunk.makeArrayBuilder(thisClassTag) + val b = makeArrayBuilder(thisClassTag) b.sizeHint(size) foreach(e => if (p(e)) b += e) Chunk.array(b.result()).asInstanceOf[Chunk[O]] @@ -209,7 +211,7 @@ abstract class Chunk[+O] extends Serializable with ChunkPlatform[O] with ChunkRu /** Maps the supplied function over each element and returns a chunk of just the defined results. */ def mapFilter[O2](f: O => Option[O2]): Chunk[O2] = { - val b = Chunk.makeArrayBuilder[Any] + val b = makeArrayBuilder[Any] b.sizeHint(size) foreach { o => val o2 = f(o) @@ -333,7 +335,7 @@ abstract class Chunk[+O] extends Serializable with ChunkPlatform[O] with ChunkRu */ def toIndexedChunk: Chunk[O] = this match { case _: Chunk.Queue[_] => - val b = Chunk.makeArrayBuilder[Any] + val b = makeArrayBuilder[Any] b.sizeHint(size) foreach(o => b += o) Chunk.array(b.result()).asInstanceOf[Chunk[O]] @@ -612,7 +614,7 @@ object Chunk else { val head = itr.next() if (itr.hasNext) { - val bldr = Chunk.makeArrayBuilder[Any] + val bldr = makeArrayBuilder[Any] bldr += head bldr ++= itr array(bldr.result()).asInstanceOf[Chunk[O]] diff --git a/core/shared/src/main/scala/fs2/Pull.scala b/core/shared/src/main/scala/fs2/Pull.scala index 856b22b92c..2ea73a9dce 100644 --- a/core/shared/src/main/scala/fs2/Pull.scala +++ b/core/shared/src/main/scala/fs2/Pull.scala @@ -327,7 +327,7 @@ object Pull extends PullLowPriority { * The `F` type must be explicitly provided (e.g., via `raiseError[IO]` * or `raiseError[Fallible]`). */ - @nowarn("cat=unused-params") + @nowarn("msg=never used") def raiseError[F[_]: RaiseThrowable](err: Throwable): Pull[F, INothing, INothing] = Fail(err) /** Creates a pull that evaluates the supplied effect `fr`, emits no @@ -649,7 +649,7 @@ object Pull extends PullLowPriority { ): Pull[F, O, Unit] = view match { case IdContP => fmoc - case bv: Bind[F, O, Unit, Unit] => + case bv: Bind[F, O, Unit, Unit] @unchecked => fmoc match { case r: Terminal[Unit] => try bv(r) @@ -696,7 +696,7 @@ object Pull extends PullLowPriority { * Each operation also generates an output of type `R` that is used * as control information for the rest of the interpretation or compilation. */ - private abstract class Action[+F[_], +O, +R] extends Pull[F, O, R] with ViewL[F, O] + private sealed abstract class Action[+F[_], +O, +R] extends Pull[F, O, R] with ViewL[F, O] /* An action that emits a non-empty chunk of outputs. */ private final case class Output[+O](values: Chunk[O]) extends Action[Pure, O, Unit] @@ -1165,8 +1165,8 @@ object Pull extends PullLowPriority { } } - viewL(stream) match { - case tst: Translate[h, G, _] @nowarn => // y = Unit + (viewL(stream): @unchecked) match { // unchecked b/c scala 3 erroneously reports exhaustiveness warning + case tst: Translate[h, G, _] @unchecked => // y = Unit val translateRunner: Run[h, X, F[End]] = new TranslateRunner(tst.fk, getCont[Unit, G, X]) val composed: h ~> F = translation.compose[h](tst.fk) go[h, X, End](scope, extendedTopLevelScope, composed, translateRunner, tst.stream) @@ -1181,14 +1181,14 @@ object Pull extends PullLowPriority { val fmrunr = new FlatMapR(getCont[Unit, G, X], fmout.fun) F.unit >> go(scope, extendedTopLevelScope, translation, fmrunr, fmout.stream) - case u: Uncons[G, y] @nowarn => + case u: Uncons[G, y] @unchecked => val v = getCont[Option[(Chunk[y], Pull[G, y, Unit])], G, X] // a Uncons is run on the same scope, without shifting. val runr = new BuildR[G, y, End] F.unit >> go(scope, extendedTopLevelScope, translation, runr, u.stream).attempt .flatMap(_.fold(goErr(_, v), _.apply(new UnconsRunR(v)))) - case s: StepLeg[G, y] @nowarn => + case s: StepLeg[G, y] @unchecked => val v = getCont[Option[Stream.StepLeg[G, y]], G, X] val runr = new BuildR[G, y, End] scope diff --git a/core/shared/src/main/scala/fs2/Stream.scala b/core/shared/src/main/scala/fs2/Stream.scala index bb56f8243e..1dafa2fd58 100644 --- a/core/shared/src/main/scala/fs2/Stream.scala +++ b/core/shared/src/main/scala/fs2/Stream.scala @@ -26,7 +26,7 @@ import scala.concurrent.TimeoutException import scala.concurrent.duration._ import cats.{Eval => _, _} import cats.data.Ior -import cats.effect.{Concurrent, IO, SyncIO} +import cats.effect.{Concurrent, SyncIO} import cats.effect.kernel._ import cats.effect.kernel.implicits._ import cats.effect.std.{Console, Queue, QueueSink, QueueSource, Semaphore} @@ -36,8 +36,6 @@ import fs2.compat._ import fs2.concurrent._ import fs2.internal._ -import scala.collection.mutable.ArrayBuffer - /** A stream producing output of type `O` and which may evaluate `F` effects. * * - '''Purely functional''' a value of type `Stream[F, O]` _describes_ an effectful computation. @@ -1183,7 +1181,7 @@ final class Stream[+F[_], +O] private[fs2] (private[fs2] val underlying: Pull[F, * res0: List[Int] = List(1, 2, 2, 3, 3, 3) * }}} */ - @nowarn("cat=unused-params") + @nowarn("msg=never used") def flatMap[F2[x] >: F[x], O2]( f: O => Stream[F2, O2] )(implicit ev: NotGiven[O <:< Nothing]): Stream[F2, O2] = @@ -2361,7 +2359,7 @@ final class Stream[+F[_], +O] private[fs2] (private[fs2] val underlying: Pull[F, ): Stream[F2, O2] = this.asInstanceOf[Stream[F, Either[Throwable, O2]]].chunks.flatMap { c => val size = c.size - val builder = Chunk.makeArrayBuilder[Any] + val builder = makeArrayBuilder[Any] builder.sizeHint(size) var i = 0 var exOpt: Option[Throwable] = None @@ -2507,14 +2505,14 @@ final class Stream[+F[_], +O] private[fs2] (private[fs2] val underlying: Pull[F, if (prev.isEmpty) Pull.done else Pull.output1(prev.take(size)) case Some((hd, tl)) => - val buffer = ArrayBuffer.empty[Chunk[O]] + val builder = makeArrayBuilder[Chunk[O]] var current = prev ++ hd while (current.size >= step) { val (nHeads, nTails) = current.splitAt(step) - buffer += nHeads.take(size) + builder += nHeads.take(size) current = nTails } - Pull.output(Chunk.buffer(buffer)) >> stepNotSmallerThanSize(tl, current) + Pull.output(Chunk.array(builder.result())) >> stepNotSmallerThanSize(tl, current) } def stepSmallerThanSize( @@ -2528,18 +2526,18 @@ final class Stream[+F[_], +O] private[fs2] (private[fs2] val underlying: Pull[F, if (prev.isEmpty) Pull.done else Pull.output1((window ++ prev).take(size)) case Some((hd, tl)) => - val buffer = ArrayBuffer.empty[Chunk[O]] + val builder = makeArrayBuilder[Chunk[O]] var w = window var current = prev ++ hd while (current.size >= step) { val (head, tail) = current.splitAt(step) val wind = w ++ head - buffer += wind + builder += wind w = wind.drop(step) current = tail } - Pull.output(Chunk.buffer(buffer)) >> stepSmallerThanSize(tl, w, current) + Pull.output(Chunk.array(builder.result())) >> stepSmallerThanSize(tl, w, current) } val resultPull = @@ -3371,7 +3369,7 @@ object Stream extends StreamLowPriority { * All elements that are available, up to the specified limit, * are dequeued and emitted as a single chunk. */ - @nowarn("cat=unused-params") + @nowarn("msg=never used") def fromQueueNoneTerminated[F[_]: Functor, A]( queue: QueueSource[F, Option[A]], limit: Int = Int.MaxValue diff --git a/core/shared/src/test/scala/fs2/ChunkGenerators.scala b/core/shared/src/test/scala/fs2/ChunkGenerators.scala index 411e6ac296..6ccd1635b3 100644 --- a/core/shared/src/test/scala/fs2/ChunkGenerators.scala +++ b/core/shared/src/test/scala/fs2/ChunkGenerators.scala @@ -40,10 +40,6 @@ trait ChunkGeneratorsLowPriority1 extends MiscellaneousGenerators { 5 -> genA.map(Chunk.singleton), 10 -> Gen.listOf(genA).map(Chunk.seq), 10 -> Gen.listOf(genA).map(_.toVector).map(Chunk.vector), - 10 -> Gen - .listOf(genA) - .map(_.toVector) - .map(as => Chunk.buffer(collection.mutable.Buffer.empty ++= as)), 10 -> Gen .listOf(genA) .map(_.toVector) diff --git a/core/shared/src/test/scala/fs2/Fs2Suite.scala b/core/shared/src/test/scala/fs2/Fs2Suite.scala index ef8ebff668..53d463184b 100644 --- a/core/shared/src/test/scala/fs2/Fs2Suite.scala +++ b/core/shared/src/test/scala/fs2/Fs2Suite.scala @@ -23,8 +23,6 @@ package fs2 import munit.{CatsEffectSuite, DisciplineSuite, ScalaCheckEffectSuite} -import scala.concurrent.ExecutionContext - abstract class Fs2Suite extends CatsEffectSuite with DisciplineSuite @@ -39,8 +37,6 @@ abstract class Fs2Suite override def munitFlakyOK = true - override val munitExecutionContext: ExecutionContext = ExecutionContext.global - /** Returns a stream that has a 10% chance of failing with an error on each output value. */ protected def spuriousFail[F[_]: RaiseThrowable, O](s: Stream[F, O]): Stream[F, O] = Stream.suspend { diff --git a/core/shared/src/test/scala/fs2/ParEvalMapSuite.scala b/core/shared/src/test/scala/fs2/ParEvalMapSuite.scala index 39e3f3f094..dfbb923f04 100644 --- a/core/shared/src/test/scala/fs2/ParEvalMapSuite.scala +++ b/core/shared/src/test/scala/fs2/ParEvalMapSuite.scala @@ -59,7 +59,7 @@ class ParEvalMapSuite extends Fs2Suite { group("order") { test("should be preserved in parEvalMap") { - forAllF { s: Stream[Pure, Int] => + forAllF { (s: Stream[Pure, Int]) => val s2 = s.covary[IO].parEvalMap(Int.MaxValue)(i => IO.sleep(math.abs(i % 3).millis).as(i)) s2.compile.toList.assertEquals(s.toList) } @@ -72,7 +72,7 @@ class ParEvalMapSuite extends Fs2Suite { def run(pipe: Pipe[IO, IO[Int], Int]) = Stream .emits(List(3, 2, 1)) - .map(i => IO.sleep(50.millis * i).as(i)) + .map(i => IO.sleep(50.millis * i.toLong).as(i)) .covary[IO] .through(pipe) .compile @@ -123,7 +123,7 @@ class ParEvalMapSuite extends Fs2Suite { def runWithLatch(length: Int, parallel: Int, pipe: Pipe[IO, IO[Unit], Unit]) = CountDownLatch[IO](parallel).flatMap { latch => - Stream(latch.release *> latch.await).repeatN(length).through(pipe).compile.drain + Stream(latch.release *> latch.await).repeatN(length.toLong).through(pipe).compile.drain } } @@ -134,7 +134,8 @@ class ParEvalMapSuite extends Fs2Suite { val amount = math.abs(i % 10) + 1 CountDownLatch[IO](amount) .flatMap { latch => - val stream = Stream(latch.release *> latch.await *> ex).repeatN(amount).covary[IO] + val stream = + Stream(latch.release *> latch.await *> ex).repeatN(amount.toLong).covary[IO] stream.parEvalMapUnordered(amount)(identity).compile.drain } .intercept[RuntimeException] @@ -147,7 +148,8 @@ class ParEvalMapSuite extends Fs2Suite { val amount = math.abs(i % 10) + 1 CountDownLatch[IO](amount) .flatMap { latch => - val stream = Stream(latch.release *> latch.await *> ex).repeatN(amount).covary[IO] + val stream = + Stream(latch.release *> latch.await *> ex).repeatN(amount.toLong).covary[IO] stream.parEvalMap(amount)(identity).compile.drain } .intercept[RuntimeException] diff --git a/core/shared/src/test/scala/fs2/StreamObserveSuite.scala b/core/shared/src/test/scala/fs2/StreamObserveSuite.scala index 94b5eaa5af..83ea6718b6 100644 --- a/core/shared/src/test/scala/fs2/StreamObserveSuite.scala +++ b/core/shared/src/test/scala/fs2/StreamObserveSuite.scala @@ -21,7 +21,6 @@ package fs2 -import scala.annotation.nowarn import scala.concurrent.duration._ import cats.effect.IO @@ -30,7 +29,6 @@ import cats.effect.kernel.Resource import cats.syntax.all._ import org.scalacheck.effect.PropF.forAllF -@nowarn("cat=w-flag-dead-code") class StreamObserveSuite extends Fs2Suite { trait Observer { def apply[O](s: Stream[IO, O])(observation: Pipe[IO, O, INothing]): Stream[IO, O] @@ -63,7 +61,9 @@ class StreamObserveSuite extends Fs2Suite { test("propagate error from source") { forAllF { (s: Stream[Pure, Int]) => - observer(s.drain ++ Stream.raiseError[IO](new Err))(_.drain).attempt.compile.toList + observer(s.drain.covaryOutput[Int] ++ Stream.raiseError[IO](new Err))( + _.drain + ).attempt.compile.toList .map { result => assertEquals(result.size, 1) assert( diff --git a/core/shared/src/test/scala/fs2/StreamSuite.scala b/core/shared/src/test/scala/fs2/StreamSuite.scala index 569ea0e9f5..3921d3c1b6 100644 --- a/core/shared/src/test/scala/fs2/StreamSuite.scala +++ b/core/shared/src/test/scala/fs2/StreamSuite.scala @@ -21,11 +21,11 @@ package fs2 -import scala.annotation.{nowarn, tailrec} +import scala.annotation.tailrec import scala.concurrent.duration._ import cats.data.Chain import cats.effect.{Deferred, IO, Outcome, Ref, Resource, SyncIO} -import cats.effect.std.{CountDownLatch, Queue} +import cats.effect.std.Queue import cats.syntax.all._ import org.scalacheck.Gen import org.scalacheck.Arbitrary.arbitrary @@ -33,7 +33,6 @@ import org.scalacheck.Prop.forAll import org.scalacheck.effect.PropF.forAllF import fs2.concurrent.SignallingRef -@nowarn("cat=w-flag-dead-code") class StreamSuite extends Fs2Suite { group("basics") { @@ -179,7 +178,7 @@ class StreamSuite extends Fs2Suite { test("4 - error in eval") { Stream - .eval(SyncIO(throw new Err)) + .eval(SyncIO[Int](throw new Err)) .map(Right(_): Either[Throwable, Int]) .handleErrorWith(t => Stream.emit(Left(t)).covary[SyncIO]) .take(1) diff --git a/core/shared/src/test/scala/fs2/StreamZipSuite.scala b/core/shared/src/test/scala/fs2/StreamZipSuite.scala index 06536feec6..65ebf44d29 100644 --- a/core/shared/src/test/scala/fs2/StreamZipSuite.scala +++ b/core/shared/src/test/scala/fs2/StreamZipSuite.scala @@ -26,12 +26,10 @@ import cats.effect.testkit.TestControl import cats.effect.{IO, SyncIO} import cats.syntax.all._ -import scala.annotation.nowarn import scala.concurrent.duration._ import org.scalacheck.Prop.forAll import org.scalacheck.effect.PropF.forAllF -@nowarn("cat=w-flag-dead-code") class StreamZipSuite extends Fs2Suite { group("zip") { @@ -372,7 +370,7 @@ class StreamZipSuite extends Fs2Suite { .toList, List("uno" -> 0, "dos" -> 3, "tres" -> 6, "cuatro" -> 10) ) - assertEquals(Stream().zipWithScan(())((_, _) => ???).toList, Nil) + assertEquals(Stream[Pure, Int]().zipWithScan(())((_, _) => ???).toList, Nil) } test("zipWithScan1") { @@ -382,7 +380,7 @@ class StreamZipSuite extends Fs2Suite { .toList, List("uno" -> 3, "dos" -> 6, "tres" -> 10, "cuatro" -> 16) ) - assertEquals(Stream().zipWithScan1(())((_, _) => ???).toList, Nil) + assertEquals(Stream[Pure, Int]().zipWithScan1(())((_, _) => ???).toList, Nil) } group("regressions") { diff --git a/core/shared/src/test/scala/fs2/TextSuite.scala b/core/shared/src/test/scala/fs2/TextSuite.scala index 3600bd5365..0bf4b40d04 100644 --- a/core/shared/src/test/scala/fs2/TextSuite.scala +++ b/core/shared/src/test/scala/fs2/TextSuite.scala @@ -271,7 +271,7 @@ class TextSuite extends Fs2Suite { } } - property("EOF") { + test("EOF") { List("\n", "\r\n", "\r").foreach { delimiter => val s = s"a$delimiter" assertEquals(Stream.emit(s).through(lines).toList, List("a", "")) @@ -294,7 +294,7 @@ class TextSuite extends Fs2Suite { } } - property("linesLimited") { + test("linesLimited") { val line = "foo" * 100 (1 to line.length).foreach { i => val stream = Stream diff --git a/io/js/src/main/scala/fs2/io/ioplatform.scala b/io/js/src/main/scala/fs2/io/ioplatform.scala index b46dfe4c28..98f1c1bf69 100644 --- a/io/js/src/main/scala/fs2/io/ioplatform.scala +++ b/io/js/src/main/scala/fs2/io/ioplatform.scala @@ -305,7 +305,7 @@ private[fs2] trait ioplatform { /** Stream of bytes read asynchronously from standard input. * Takes a dummy `Int` parameter for source-compatibility with JVM. */ - @nowarn("cat=unused") + @nowarn("msg=never used") def stdin[F[_]: Async](ignored: Int): Stream[F, Byte] = stdin /** Pipe of bytes that writes emitted values to standard output asynchronously. */ @@ -333,7 +333,7 @@ private[fs2] trait ioplatform { /** Stream of `String` read asynchronously from standard input decoded in UTF-8. * Takes a dummy `Int` parameter for source-compatibility with JVM. */ - @nowarn("cat=unused") + @nowarn("msg=never used") def stdinUtf8[F[_]: Async](ignored: Int): Stream[F, String] = stdinAsync.through(text.utf8.decode) diff --git a/io/js/src/test/scala/fs2/io/net/tls/TLSSuite.scala b/io/js/src/test/scala/fs2/io/net/tls/TLSSuite.scala index 02ca37be3d..dd38b8afc5 100644 --- a/io/js/src/test/scala/fs2/io/net/tls/TLSSuite.scala +++ b/io/js/src/test/scala/fs2/io/net/tls/TLSSuite.scala @@ -64,7 +64,7 @@ object JKS extends js.Any { def key: String = js.native } - @nowarn("cat=unused-params") + @nowarn("msg=never used") def toPem(buffer: bufferMod.global.Buffer, password: String): js.Dictionary[CertKey] = js.native } diff --git a/io/jvm/src/main/scala/fs2/io/ioplatform.scala b/io/jvm/src/main/scala/fs2/io/ioplatform.scala index 3c0fba366d..3150c3b46a 100644 --- a/io/jvm/src/main/scala/fs2/io/ioplatform.scala +++ b/io/jvm/src/main/scala/fs2/io/ioplatform.scala @@ -29,7 +29,7 @@ import cats.effect.kernel.Deferred import cats.syntax.all._ import fs2.io.internal.PipedStreamBuffer -import java.io.{IOException, InputStream, OutputStream} +import java.io.{InputStream, OutputStream} import java.nio.charset.Charset import java.nio.charset.StandardCharsets import scala.reflect.ClassTag diff --git a/io/jvm/src/main/scala/fs2/io/net/tls/DTLSSocket.scala b/io/jvm/src/main/scala/fs2/io/net/tls/DTLSSocket.scala index 95b25d0f11..5299631a4d 100644 --- a/io/jvm/src/main/scala/fs2/io/net/tls/DTLSSocket.scala +++ b/io/jvm/src/main/scala/fs2/io/net/tls/DTLSSocket.scala @@ -25,7 +25,6 @@ package net package tls import java.net.NetworkInterface -import javax.net.ssl.SSLSession import cats.Applicative import cats.effect.kernel.{Async, Resource, Sync} diff --git a/io/jvm/src/main/scala/fs2/io/net/tls/TLSEngine.scala b/io/jvm/src/main/scala/fs2/io/net/tls/TLSEngine.scala index 430cf30309..2c61e0a020 100644 --- a/io/jvm/src/main/scala/fs2/io/net/tls/TLSEngine.scala +++ b/io/jvm/src/main/scala/fs2/io/net/tls/TLSEngine.scala @@ -24,7 +24,7 @@ package io package net package tls -import javax.net.ssl.{SSLEngine, SSLEngineResult, SSLSession} +import javax.net.ssl.{SSLEngine, SSLEngineResult} import cats.Applicative import cats.effect.kernel.{Async, Sync} diff --git a/io/jvm/src/test/scala/fs2/io/net/tls/TLSDebugExample.scala b/io/jvm/src/test/scala/fs2/io/net/tls/TLSDebugExample.scala index db0a56ff27..3068d85912 100644 --- a/io/jvm/src/test/scala/fs2/io/net/tls/TLSDebugExample.scala +++ b/io/jvm/src/test/scala/fs2/io/net/tls/TLSDebugExample.scala @@ -63,7 +63,8 @@ class TLSDebugTest extends Fs2Suite { Network[IO].tlsContext.system.flatMap { ctx => TLSDebug .debug[IO](ctx, address) - .flatMap(l => IO(println(l))) + // .flatMap(IO.println) + .void } test("google")(run(SocketAddress(host"google.com", port"443"))) diff --git a/io/shared/src/test/scala/fs2/io/file/PathSuite.scala b/io/shared/src/test/scala/fs2/io/file/PathSuite.scala index 4b68f9581e..ac92eabc6d 100644 --- a/io/shared/src/test/scala/fs2/io/file/PathSuite.scala +++ b/io/shared/src/test/scala/fs2/io/file/PathSuite.scala @@ -30,7 +30,6 @@ import org.scalacheck.Arbitrary import org.scalacheck.Cogen import org.scalacheck.Gen import org.scalacheck.Prop.forAll -import org.scalacheck.Prop.propBoolean class PathSuite extends Fs2Suite { @@ -101,7 +100,7 @@ class PathSuite extends Fs2Suite { test("startsWith/endsWith") { forAll { (start: Path, end: Path) => - (start.toString.nonEmpty && end.toString.nonEmpty) ==> { + if (start.toString.nonEmpty && end.toString.nonEmpty) { val path = start.resolve(end) // TODO // assert(path.startsWith(start), s"$path doesn't start with $start") diff --git a/protocols/shared/src/test/scala/fs2/protocols/ip/Ipv4HeaderTest.scala b/protocols/shared/src/test/scala/fs2/protocols/ip/Ipv4HeaderTest.scala index aa75f24a75..27a28de99d 100644 --- a/protocols/shared/src/test/scala/fs2/protocols/ip/Ipv4HeaderTest.scala +++ b/protocols/shared/src/test/scala/fs2/protocols/ip/Ipv4HeaderTest.scala @@ -41,7 +41,7 @@ class Ipv4HeaderTest extends Fs2Suite { private val src = hex"0ae081b2".bits private val dst = hex"0ae081ab".bits private val dataLength = 80 - private val data = BitVector.high(dataLength) + private val data = BitVector.high(dataLength.toLong) test("decode IPv4 packet without options") { val headerLength = bin"0101" // 5 32-bit words diff --git a/scodec/shared/src/test/scala/fs2/interop/scodec/MpegExample.scala b/scodec/shared/src/test/scala/fs2/interop/scodec/MpegExample.scala index bb3e798159..e5720ae373 100644 --- a/scodec/shared/src/test/scala/fs2/interop/scodec/MpegExample.scala +++ b/scodec/shared/src/test/scala/fs2/interop/scodec/MpegExample.scala @@ -174,7 +174,7 @@ object PcapCodec { implicit def pcapRecord(implicit ordering: ByteOrdering): Codec[PcapRecord] = ("record_header" | pcapRecordHeader) .flatPrepend { hdr => - ("record_data" | bits(hdr.includedLength * 8)).hlist + ("record_data" | bits(hdr.includedLength * 8)).tuple } .as[PcapRecord] @@ -183,7 +183,7 @@ object PcapCodec { implicit val pcapFile: Codec[PcapFile] = pcapHeader .flatPrepend { hdr => - vector(pcapRecord(hdr.ordering)).hlist + vector(pcapRecord(hdr.ordering)).tuple } .as[PcapFile] }