Skip to content

Commit f51e5bd

Browse files
authored
Merge pull request #2448 from vasilmkd/warnings
Compile without warnings (2.5.x)
2 parents d78ca55 + 7540d63 commit f51e5bd

39 files changed

+272
-111
lines changed

benchmark/src/main/scala/fs2/benchmark/ChunkBenchmark.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ class ChunkBenchmark {
5151
}
5252

5353
@Benchmark
54-
def concat(): Unit =
54+
def concat(): Unit = {
5555
Chunk.concat(chunkSeq, sizeHint)
56+
()
57+
}
5658

5759
@Benchmark
5860
def traverse(): Boolean = {

benchmark/src/main/scala/fs2/benchmark/QueueBenchmark.scala

+6-4
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ class QueueBenchmark {
4343
Queue
4444
.unbounded[IO, Int]
4545
.flatMap { q =>
46-
Concurrent[IO].start(Stream.constant(1, n).take(size).through(q.enqueue).compile.drain) >>
47-
q.dequeue.take(size).compile.drain
46+
Concurrent[IO].start(
47+
Stream.constant(1, n).take(size.toLong).through(q.enqueue).compile.drain
48+
) >>
49+
q.dequeue.take(size.toLong).compile.drain
4850
}
4951
.unsafeRunSync()
5052

@@ -54,9 +56,9 @@ class QueueBenchmark {
5456
.unbounded[IO, Chunk[Int]]
5557
.flatMap { q =>
5658
Concurrent[IO].start(
57-
Stream.constant(1, n).take(size).chunks.through(q.enqueue).compile.drain
59+
Stream.constant(1, n).take(size.toLong).chunks.through(q.enqueue).compile.drain
5860
) >>
59-
q.dequeue.flatMap(Stream.chunk).take(size).compile.drain
61+
q.dequeue.flatMap(Stream.chunk).take(size.toLong).compile.drain
6062
}
6163
.unsafeRunSync()
6264
}

benchmark/src/main/scala/fs2/benchmark/StreamBenchmark.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class StreamBenchmark {
8686

8787
@Benchmark
8888
def eval(): Unit =
89-
Stream.repeatEval(IO(())).take(n).compile.last.unsafeRunSync().get
89+
Stream.repeatEval(IO(())).take(n.toLong).compile.last.unsafeRunSync().get
9090

9191
@Benchmark
9292
def toVector(): Vector[Int] =

core/jvm/src/main/scala/fs2/compression.scala

-6
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ object compression {
386386
in.pull.unconsNonEmpty.flatMap {
387387
case Some((deflatedChunk, deflatedStream)) =>
388388
_inflate_chunk(
389-
inflateParams,
390389
inflater,
391390
crc32,
392391
deflatedChunk,
@@ -403,7 +402,6 @@ object compression {
403402
}
404403

405404
private def _inflate_chunk[F[_]](
406-
inflaterParams: InflateParams,
407405
inflater: Inflater,
408406
crc32: Option[CRC32],
409407
chunk: Chunk[Byte],
@@ -473,7 +471,6 @@ object compression {
473471
_.pull.unconsNonEmpty.flatMap {
474472
case Some((deflatedChunk, deflatedStream)) =>
475473
_inflate_chunk(
476-
inflateParams,
477474
inflater,
478475
crc32,
479476
deflatedChunk,
@@ -1237,9 +1234,6 @@ object compression {
12371234
if (length > 0) Chunk.Bytes(values, 0, length)
12381235
else Chunk.empty[Byte]
12391236

1240-
private def copyAsChunkBytes(values: Array[Byte]): Chunk[Byte] =
1241-
copyAsChunkBytes(values, values.length)
1242-
12431237
private def copyAsChunkBytes(values: Array[Byte], length: Int): Chunk[Byte] =
12441238
if (length > 0) {
12451239
val target = new Array[Byte](length)

core/jvm/src/test/scala/fs2/CompressionSuite.scala

+7-7
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,14 @@ class CompressionSuite extends Fs2Suite {
281281
) =>
282282
val expectedFileName = Option(toEncodableFileName(s))
283283
val expectedComment = Option(toEncodableComment(s))
284-
val expectedMTime = Option(Instant.ofEpochSecond(epochSeconds))
284+
val expectedMTime = Option(Instant.ofEpochSecond(epochSeconds.toLong))
285285
Stream
286286
.chunk(Chunk.bytes(s.getBytes))
287287
.rechunkRandomlyWithSeed(0.1, 2)(System.nanoTime())
288288
.through(
289289
gzip[IO](
290290
fileName = Some(s),
291-
modificationTime = Some(Instant.ofEpochSecond(epochSeconds)),
291+
modificationTime = Some(Instant.ofEpochSecond(epochSeconds.toLong)),
292292
comment = Some(s),
293293
DeflateParams(
294294
bufferSize = 8192,
@@ -326,14 +326,14 @@ class CompressionSuite extends Fs2Suite {
326326
) =>
327327
val expectedFileName = Option(toEncodableFileName(s))
328328
val expectedComment = Option(toEncodableComment(s))
329-
val expectedMTime = Option(Instant.ofEpochSecond(epochSeconds))
329+
val expectedMTime = Option(Instant.ofEpochSecond(epochSeconds.toLong))
330330
Stream
331331
.chunk(Chunk.bytes(s.getBytes))
332332
.rechunkRandomlyWithSeed(0.1, 2)(System.nanoTime())
333333
.through(
334334
gzip[IO](
335335
fileName = Some(s),
336-
modificationTime = Some(Instant.ofEpochSecond(epochSeconds)),
336+
modificationTime = Some(Instant.ofEpochSecond(epochSeconds.toLong)),
337337
comment = Some(s),
338338
DeflateParams(
339339
bufferSize = 1031,
@@ -371,14 +371,14 @@ class CompressionSuite extends Fs2Suite {
371371
) =>
372372
val expectedFileName = Option(toEncodableFileName(s))
373373
val expectedComment = Option(toEncodableComment(s))
374-
val expectedMTime = Option(Instant.ofEpochSecond(epochSeconds))
374+
val expectedMTime = Option(Instant.ofEpochSecond(epochSeconds.toLong))
375375
Stream
376376
.chunk(Chunk.bytes(s.getBytes))
377377
.rechunkRandomlyWithSeed(0.1, 2)(System.nanoTime())
378378
.through(
379379
gzip[IO](
380380
fileName = Some(s),
381-
modificationTime = Some(Instant.ofEpochSecond(epochSeconds)),
381+
modificationTime = Some(Instant.ofEpochSecond(epochSeconds.toLong)),
382382
comment = Some(s),
383383
DeflateParams(
384384
bufferSize = 509,
@@ -420,7 +420,7 @@ class CompressionSuite extends Fs2Suite {
420420
.through(
421421
gzip(
422422
fileName = Some(s),
423-
modificationTime = Some(Instant.ofEpochSecond(epochSeconds)),
423+
modificationTime = Some(Instant.ofEpochSecond(epochSeconds.toLong)),
424424
comment = Some(s),
425425
DeflateParams(
426426
bufferSize = 1024,

core/shared/src/main/scala/fs2/Pull.scala

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import cats.syntax.all._
2727
import fs2.internal._
2828
import fs2.internal.FreeC.{Eval, Result}
2929

30+
import scala.annotation.nowarn
3031
import scala.concurrent.duration.{FiniteDuration, TimeUnit}
3132

3233
/** A `p: Pull[F,O,R]` reads values from one or more streams, returns a
@@ -173,6 +174,7 @@ object Pull extends PullLowPriority {
173174
*
174175
* The `F` type must be explicitly provided (e.g., via `raiseError[IO]` or `raiseError[Fallible]`).
175176
*/
177+
@nowarn("cat=unused-params")
176178
def raiseError[F[_]: RaiseThrowable](err: Throwable): Pull[F, INothing, INothing] =
177179
new Pull(Result.Fail(err))
178180

core/shared/src/main/scala/fs2/Stream.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import fs2.internal.FreeC.{Acquire, Eval, GetScope, Output, Result}
3131
import fs2.internal._
3232
import java.io.PrintStream
3333

34-
import scala.annotation.tailrec
34+
import scala.annotation.{nowarn, tailrec}
3535
import scala.concurrent.TimeoutException
3636
import scala.concurrent.duration._
3737
import cats.data.Ior
@@ -1058,6 +1058,7 @@ final class Stream[+F[_], +O] private[fs2] (private val free: FreeC[F, O, Unit])
10581058

10591059
/** Alias for `evalMapChunk(o => f(o).as(o))`.
10601060
*/
1061+
@nowarn("cat=unused-params")
10611062
def evalTapChunk[F2[x] >: F[x]: Functor: Applicative, O2](f: O => F2[O2]): Stream[F2, O] =
10621063
evalMapChunk(o => f(o).as(o))
10631064

@@ -1095,6 +1096,7 @@ final class Stream[+F[_], +O] private[fs2] (private val free: FreeC[F, O, Unit])
10951096
* Note: The result Stream will consist of chunks that are empty or 1-element-long.
10961097
* If you want to operate on chunks after using it, consider buffering, e.g. by using [[buffer]].
10971098
*/
1099+
@nowarn("cat=unused-params")
10981100
def evalFilter[F2[x] >: F[x]: Functor](f: O => F2[Boolean]): Stream[F2, O] =
10991101
flatMap(o => Stream.eval(f(o)).ifM(Stream.emit(o), Stream.empty))
11001102

@@ -1113,6 +1115,7 @@ final class Stream[+F[_], +O] private[fs2] (private val free: FreeC[F, O, Unit])
11131115
* Note: The result Stream will consist of chunks that are empty or 1-element-long.
11141116
* If you want to operate on chunks after using it, consider buffering, e.g. by using [[buffer]].
11151117
*/
1118+
@nowarn("cat=unused-params")
11161119
def evalFilterNot[F2[x] >: F[x]: Functor](f: O => F2[Boolean]): Stream[F2, O] =
11171120
flatMap(o => Stream.eval(f(o)).ifM(Stream.empty, Stream.emit(o)))
11181121

@@ -2274,6 +2277,7 @@ final class Stream[+F[_], +O] private[fs2] (private val free: FreeC[F, O, Unit])
22742277

22752278
/** Rechunks the stream such that output chunks are within [inputChunk.size * minFactor, inputChunk.size * maxFactor].
22762279
*/
2280+
@nowarn("cat=unused-params")
22772281
def rechunkRandomly[F2[x] >: F[x]: Sync](
22782282
minFactor: Double = 0.1,
22792283
maxFactor: Double = 2.0
@@ -3380,6 +3384,7 @@ object Stream extends StreamLowPriority {
33803384
* res0: Either[Throwable,Unit] = Left(java.lang.RuntimeException)
33813385
* }}}
33823386
*/
3387+
@nowarn("cat=unused-params")
33833388
def raiseError[F[_]: RaiseThrowable](e: Throwable): Stream[F, INothing] =
33843389
new Stream(Result.Fail(e))
33853390

core/shared/src/main/scala/fs2/internal/Algebra.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ private[fs2] object FreeC {
447447
}
448448

449449
view.step match {
450-
case output: Output[X] =>
450+
case output: Output[_] =>
451451
interruptGuard(scope)(
452452
F.pure(Out(output.values, scope, view.next(FreeC.Result.unit)))
453453
)

core/shared/src/main/scala/fs2/internal/CompileScope.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ private[fs2] final class CompileScope[F[_]] private (
179179
F.uncancelable {
180180
F.flatMap(F.attempt(fr)) {
181181
case Right(r) =>
182-
val finalizer = (ec: ExitCase[Throwable]) => F.suspend(release(r, ec))
182+
val finalizer = (ec: ExitCase[Throwable]) => F.defer(release(r, ec))
183183
F.flatMap(resource.acquired(finalizer)) { result =>
184184
if (result.exists(identity)) {
185185
F.flatMap(register(resource)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2013 Functional Streams for Scala
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
* this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to
7+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
* the Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
package fs2
23+
24+
import org.scalacheck.Shrink
25+
26+
import scala.collection.immutable.{Stream => StdStream}
27+
28+
private[fs2] trait ChunkGeneratorsCompat {
29+
30+
protected implicit def shrinkChunk[A]: Shrink[Chunk[A]] =
31+
Shrink[Chunk[A]](c => removeChunks(c.size, c))
32+
33+
// The removeChunks function and the interleave function were ported from Scalacheck,
34+
// from Shrink.scala, licensed under a Revised BSD license.
35+
//
36+
// /*-------------------------------------------------------------------------*\
37+
// ** ScalaCheck **
38+
// ** Copyright (c) 2007-2016 Rickard Nilsson. All rights reserved. **
39+
// ** http://www.scalacheck.org **
40+
// ** **
41+
// ** This software is released under the terms of the Revised BSD License. **
42+
// ** There is NO WARRANTY. See the file LICENSE for the full text. **
43+
// \*------------------------------------------------------------------------ */
44+
45+
private def removeChunks[A](size: Int, xs: Chunk[A]): StdStream[Chunk[A]] =
46+
if (xs.isEmpty) StdStream.empty
47+
else if (xs.size == 1) StdStream(Chunk.empty)
48+
else {
49+
val n1 = size / 2
50+
val n2 = size - n1
51+
lazy val xs1 = xs.take(n1)
52+
lazy val xs2 = xs.drop(n1)
53+
lazy val xs3 =
54+
for (ys1 <- removeChunks(n1, xs1) if !ys1.isEmpty) yield Chunk.concat(List(ys1, xs2))
55+
lazy val xs4 =
56+
for (ys2 <- removeChunks(n2, xs2) if !ys2.isEmpty) yield Chunk.concat(List(xs1, ys2))
57+
58+
StdStream.cons(xs1, StdStream.cons(xs2, interleave(xs3, xs4)))
59+
}
60+
61+
private def interleave[A](xs: StdStream[A], ys: StdStream[A]): StdStream[A] =
62+
if (xs.isEmpty) ys else if (ys.isEmpty) xs else xs.head +: ys.head +: (xs.tail ++ ys.tail)
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2013 Functional Streams for Scala
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
* this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to
7+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
* the Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
package fs2
23+
24+
import org.scalacheck.Shrink
25+
26+
import scala.collection.immutable.LazyList
27+
28+
private[fs2] trait ChunkGeneratorsCompat {
29+
30+
protected implicit def shrinkChunk[A]: Shrink[Chunk[A]] =
31+
Shrink.withLazyList[Chunk[A]](c => removeChunks(c.size, c))
32+
33+
// The removeChunks function and the interleave function were ported from Scalacheck,
34+
// from Shrink.scala, licensed under a Revised BSD license.
35+
//
36+
// /*-------------------------------------------------------------------------*\
37+
// ** ScalaCheck **
38+
// ** Copyright (c) 2007-2016 Rickard Nilsson. All rights reserved. **
39+
// ** http://www.scalacheck.org **
40+
// ** **
41+
// ** This software is released under the terms of the Revised BSD License. **
42+
// ** There is NO WARRANTY. See the file LICENSE for the full text. **
43+
// \*------------------------------------------------------------------------ */
44+
45+
private def removeChunks[A](size: Int, xs: Chunk[A]): LazyList[Chunk[A]] =
46+
if (xs.isEmpty) LazyList.empty
47+
else if (xs.size == 1) LazyList(Chunk.empty)
48+
else {
49+
val n1 = size / 2
50+
val n2 = size - n1
51+
lazy val xs1 = xs.take(n1)
52+
lazy val xs2 = xs.drop(n1)
53+
lazy val xs3 =
54+
for (ys1 <- removeChunks(n1, xs1) if !ys1.isEmpty) yield Chunk.concat(List(ys1, xs2))
55+
lazy val xs4 =
56+
for (ys2 <- removeChunks(n2, xs2) if !ys2.isEmpty) yield Chunk.concat(List(xs1, ys2))
57+
58+
LazyList.cons(xs1, LazyList.cons(xs2, interleave(xs3, xs4)))
59+
}
60+
61+
private def interleave[A](xs: LazyList[A], ys: LazyList[A]): LazyList[A] =
62+
if (xs.isEmpty) ys else if (ys.isEmpty) xs else xs.head +: ys.head +: (xs.tail ++ ys.tail)
63+
}

core/shared/src/test/scala-2.13/fs2/ChunkPlatformSuite.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import Arbitrary.arbitrary
3131
class ChunkPlatformSuite extends Fs2Suite {
3232

3333
private implicit def genArraySeq[A: Arbitrary: ClassTag]: Arbitrary[ArraySeq[A]] =
34-
Arbitrary(Gen.listOf(arbitrary[A]).map(ArraySeq.from))
34+
Arbitrary(Gen.listOf(arbitrary[A]).map(ArraySeq.from(_)(implicitly[ClassTag[A]])))
3535
private implicit def genMutableArraySeq[A: Arbitrary: ClassTag]: Arbitrary[mutable.ArraySeq[A]] =
3636
Arbitrary(arbitrary[ArraySeq[A]].map(_.to(mutable.ArraySeq)))
3737

0 commit comments

Comments
 (0)