Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed all 2.13 warnings, reenabled fatalWarning on 2.13 #2914

Merged
merged 6 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .jvmopts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-Dfile.encoding=UTF8
-Xms1G
-Xmx4G
-XX:ReservedCodeCacheSize=250M
-Xmx5G
-XX:ReservedCodeCacheSize=500M
-XX:+TieredCompilation
-XX:+UseParallelGC
-XX:+UseParallelGC
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package alleycats.compat
import scala.annotation.{Annotation, StaticAnnotation}

private[alleycats] object scalaVersionSpecific {

/**
* a trick to suppress unused import warning for this object
*/
class suppressUnusedImportWarningForScalaVersionSpecific extends Annotation with StaticAnnotation

implicit class traversableOnceExtension[A](private val to: TraversableOnce[A]) extends AnyVal {
def iterator: Iterator[A] = to.toIterator
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package alleycats
package compat
import scala.annotation.{Annotation, StaticAnnotation}

private[alleycats] object scalaVersionSpecific {

/**
* a trick to suppress unused import warning for this object
*/
class suppressUnusedImportWarningForScalaVersionSpecific extends Annotation with StaticAnnotation

}
7 changes: 5 additions & 2 deletions alleycats-core/src/main/scala/alleycats/std/set.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package alleycats.std
package alleycats
package std

import cats.{Applicative, Eval, Foldable, Monad, Monoid, Traverse, TraverseFilter}

import scala.annotation.tailrec
import compat.scalaVersionSpecific._

object set extends SetInstances

@suppressUnusedImportWarningForScalaVersionSpecific
trait SetInstances {
// This method advertises parametricity, but relies on using
// universal hash codes and equality, which hurts our ability to
Expand Down Expand Up @@ -86,7 +89,7 @@ trait SetInstances {
go(idx - 1, it)
}
} else None
if (idx < Int.MaxValue && idx >= 0L) go(idx.toInt, fa.toIterator) else None
if (idx < Int.MaxValue && idx >= 0L) go(idx.toInt, fa.iterator) else None
}

override def size[A](fa: Set[A]): Long = fa.size.toLong
Expand Down
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -816,12 +816,12 @@ def commonScalacOptions(scalaVersion: String) =
"-unchecked",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard"
"-Ywarn-value-discard",
"-Xfatal-warnings",
"-deprecation"
) ++ (if (priorTo2_13(scalaVersion))
Seq(
"-Yno-adapted-args",
"-Xfatal-warnings", // TODO: add the following two back to 2.13
"-deprecation",
"-Xfuture"
)
else
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/scala/cats/Inject.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package cats

import kernel.compat.scalaVersionMoreSpecific._

/**
* Inject is a type class providing an injection from type `A` into
* type `B`. An injection is a function `inj` which does not destroy
Expand All @@ -25,6 +27,7 @@ abstract class Inject[A, B] {
final def unapply(b: B): Option[A] = prj(b)
}

@suppressUnusedImportWarningForScalaVersionMoreSpecific
sealed abstract private[cats] class InjectInstances {
implicit def catsReflexiveInjectInstance[A]: Inject[A, A] =
new Inject[A, A] {
Expand All @@ -44,7 +47,7 @@ sealed abstract private[cats] class InjectInstances {
new Inject[A, Either[C, B]] {
val inj = (a: A) => Right(I.inj(a))

val prj = (_: Either[C, B]).right.toOption.flatMap(I.prj)
val prj = (_: Either[C, B]).toOption.flatMap(I.prj)
}

}
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/scala/cats/InjectK.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cats

import cats.arrow.FunctionK
import cats.data.EitherK
import kernel.compat.scalaVersionMoreSpecific._

/**
* InjectK is a type class providing an injection from type
Expand Down Expand Up @@ -32,6 +33,7 @@ abstract class InjectK[F[_], G[_]] {
final def unapply[A](ga: G[A]): Option[F[A]] = prj(ga)
}

@suppressUnusedImportWarningForScalaVersionMoreSpecific
sealed abstract private[cats] class InjectKInstances {
implicit def catsReflexiveInjectKInstance[F[_]]: InjectK[F, F] =
new InjectK[F, F] {
Expand All @@ -51,7 +53,7 @@ sealed abstract private[cats] class InjectKInstances {
new InjectK[F, EitherK[H, G, ?]] {
val inj = λ[FunctionK[G, EitherK[H, G, ?]]](EitherK.rightc(_)).compose(I.inj)

val prj = λ[FunctionK[EitherK[H, G, ?], λ[α => Option[F[α]]]]](_.run.right.toOption.flatMap(I.prj(_)))
val prj = λ[FunctionK[EitherK[H, G, ?], λ[α => Option[F[α]]]]](_.run.toOption.flatMap(I.prj(_)))
}
}

Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/cats/Invariant.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import cats.kernel.compat.scalaVersionSpecific._
}
}

@suppressUnusedImportWarningForScalaVersionSpecific
object Invariant {
implicit val catsInvariantMonoid: Invariant[Monoid] = new Invariant[Monoid] {

Expand Down
4 changes: 3 additions & 1 deletion core/src/main/scala/cats/data/NonEmptySet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import cats.kernel._
import cats.syntax.order._

import scala.collection.immutable._
import kernel.compat.scalaVersionSpecific._

private[data] object NonEmptySetImpl extends NonEmptySetInstances with Newtype {

Expand All @@ -48,6 +49,7 @@ private[data] object NonEmptySetImpl extends NonEmptySetInstances with Newtype {
new NonEmptySetOps(value)
}

@suppressUnusedImportWarningForScalaVersionSpecific
sealed class NonEmptySetOps[A](val value: NonEmptySet[A]) {

implicit private val ordering: Ordering[A] = toSortedSet.ordering
Expand Down Expand Up @@ -335,7 +337,7 @@ sealed class NonEmptySetOps[A](val value: NonEmptySet[A]) {
*/
def zipWith[B, C](b: NonEmptySet[B])(f: (A, B) => C)(implicit C: Order[C]): NonEmptySet[C] = {
implicit val cOrdering = C.toOrdering
NonEmptySetImpl.create((toSortedSet, b.toSortedSet).zipped.map(f))
NonEmptySetImpl.create((toSortedSet.lazyZip(b.toSortedSet)).map(f))
}

/**
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/scala/cats/data/NonEmptyVector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import cats.data.NonEmptyVector.ZipNonEmptyVector
import scala.annotation.tailrec
import scala.collection.immutable.{TreeSet, VectorBuilder}
import cats.instances.vector._
import kernel.compat.scalaVersionSpecific._

/**
* A data type which represents a `Vector` guaranteed to contain at least one element.
Expand Down Expand Up @@ -218,7 +219,7 @@ final class NonEmptyVector[+A] private (val toVector: Vector[A]) extends AnyVal
* }}}
*/
def zipWith[B, C](b: NonEmptyVector[B])(f: (A, B) => C): NonEmptyVector[C] =
NonEmptyVector.fromVectorUnsafe((toVector, b.toVector).zipped.map(f))
NonEmptyVector.fromVectorUnsafe(toVector.lazyZip(b.toVector).map(f))

def reverse: NonEmptyVector[A] =
new NonEmptyVector(toVector.reverse)
Expand All @@ -233,6 +234,7 @@ final class NonEmptyVector[+A] private (val toVector: Vector[A]) extends AnyVal
new NonEmptyVector(toVector.sorted(AA.toOrdering))
}

@suppressUnusedImportWarningForScalaVersionSpecific
sealed abstract private[data] class NonEmptyVectorInstances {

implicit val catsDataInstancesForNonEmptyVector: SemigroupK[NonEmptyVector]
Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/cats/data/OneAnd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ final case class OneAnd[F[_], A](head: A, tail: F[A]) {
s"OneAnd(${A.show(head)}, ${FA.show(tail)})"
}

@suppressUnusedImportWarningForScalaVersionSpecific
sealed abstract private[data] class OneAndInstances extends OneAndLowPriority0 {

implicit def catsDataParallelForOneAnd[A, M[_]: Alternative, F[_]: Alternative](
Expand Down
10 changes: 6 additions & 4 deletions core/src/main/scala/cats/data/ZipList.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package cats.data
package cats
package data

import cats.{CommutativeApply, Eq}
import cats.instances.list.catsKernelStdEqForList
import instances.list.catsKernelStdEqForList
import kernel.compat.scalaVersionSpecific._

class ZipList[A](val value: List[A]) extends AnyVal

@suppressUnusedImportWarningForScalaVersionSpecific
object ZipList {

def apply[A](value: List[A]): ZipList[A] = new ZipList(value)
Expand All @@ -15,7 +17,7 @@ object ZipList {
ZipList(fa.value.map(f))

def ap[A, B](ff: ZipList[A => B])(fa: ZipList[A]): ZipList[B] =
ZipList((ff.value, fa.value).zipped.map(_.apply(_)))
ZipList(ff.value.lazyZip(fa.value).map(_.apply(_)))

override def product[A, B](fa: ZipList[A], fb: ZipList[B]): ZipList[(A, B)] =
ZipList(fa.value.zip(fb.value))
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/cats/data/ZipStream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kernel.compat.scalaVersionSpecific._

class ZipStream[A](val value: LazyList[A]) extends AnyVal

@suppressUnusedImportWarningForScalaVersionSpecific
object ZipStream {

def apply[A](value: LazyList[A]): ZipStream[A] = new ZipStream(value)
Expand All @@ -18,7 +19,7 @@ object ZipStream {
ZipStream(fa.value.map(f))

def ap[A, B](ff: ZipStream[A => B])(fa: ZipStream[A]): ZipStream[B] =
ZipStream((ff.value, fa.value).zipped.map(_.apply(_)))
ZipStream(ff.value.lazyZip(fa.value).map(_.apply(_)))

override def product[A, B](fa: ZipStream[A], fb: ZipStream[B]): ZipStream[(A, B)] =
ZipStream(fa.value.zip(fb.value))
Expand Down
10 changes: 6 additions & 4 deletions core/src/main/scala/cats/data/ZipVector.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package cats.data
package cats
package data

import cats.{CommutativeApply, Eq}
import cats.instances.vector._
import instances.vector._
import kernel.compat.scalaVersionSpecific._

class ZipVector[A](val value: Vector[A]) extends AnyVal

@suppressUnusedImportWarningForScalaVersionSpecific
object ZipVector {

def apply[A](value: Vector[A]): ZipVector[A] = new ZipVector(value)
Expand All @@ -14,7 +16,7 @@ object ZipVector {
override def map[A, B](fa: ZipVector[A])(f: (A) => B): ZipVector[B] =
ZipVector(fa.value.map(f))
def ap[A, B](ff: ZipVector[A => B])(fa: ZipVector[A]): ZipVector[B] =
ZipVector((ff.value, fa.value).zipped.map(_.apply(_)))
ZipVector(ff.value.lazyZip(fa.value).map(_.apply(_)))

}

Expand Down
3 changes: 3 additions & 0 deletions core/src/main/scala/cats/data/package.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cats
import kernel.compat.scalaVersionSpecific._
import compat.lazyList.toLazyList

package object data {

type NonEmptyStream[A] = OneAnd[LazyList, A]
Expand All @@ -15,6 +16,8 @@ package object data {

def NonEmptyStream[A](head: A, tail: LazyList[A] = LazyList.empty): NonEmptyStream[A] =
OneAnd(head, tail)

@suppressUnusedImportWarningForScalaVersionSpecific
def NonEmptyStream[A](head: A, tail: A*): NonEmptyStream[A] =
OneAnd(head, toLazyList(tail))

Expand Down
18 changes: 9 additions & 9 deletions core/src/main/scala/cats/instances/either.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trait EitherInstances extends cats.kernel.instances.EitherInstances {
def pure[B](b: B): Either[A, B] = Right(b)

def flatMap[B, C](fa: Either[A, B])(f: B => Either[A, C]): Either[A, C] =
fa.right.flatMap(f)
fa.flatMap(f)

def handleErrorWith[B](fea: Either[A, B])(f: A => Either[A, B]): Either[A, B] =
fea match {
Expand All @@ -46,7 +46,7 @@ trait EitherInstances extends cats.kernel.instances.EitherInstances {
def raiseError[B](e: A): Either[A, B] = Left(e)

override def map[B, C](fa: Either[A, B])(f: B => C): Either[A, C] =
fa.right.map(f)
fa.map(f)

@tailrec
def tailRecM[B, C](b: B)(f: B => Either[A, Either[B, C]]): Either[A, C] =
Expand All @@ -63,7 +63,7 @@ trait EitherInstances extends cats.kernel.instances.EitherInstances {
override def map2Eval[B, C, Z](fb: Either[A, B], fc: Eval[Either[A, C]])(f: (B, C) => Z): Eval[Either[A, Z]] =
fb match {
case l @ Left(_) => Now(EitherUtil.rightCast(l))
case Right(b) => fc.map(_.right.map(f(b, _)))
case Right(b) => fc.map(_.map(f(b, _)))
}

def traverse[F[_], B, C](fa: Either[A, B])(f: B => F[C])(implicit F: Applicative[F]): F[Either[A, C]] =
Expand Down Expand Up @@ -103,18 +103,18 @@ trait EitherInstances extends cats.kernel.instances.EitherInstances {
fab.ensureOr(error)(predicate)

override def reduceLeftToOption[B, C](fab: Either[A, B])(f: B => C)(g: (C, B) => C): Option[C] =
fab.right.map(f).toOption
fab.map(f).toOption

override def reduceRightToOption[B, C](
fab: Either[A, B]
)(f: B => C)(g: (B, Eval[C]) => Eval[C]): Eval[Option[C]] =
Now(fab.right.map(f).toOption)
Now(fab.map(f).toOption)

override def reduceLeftOption[B](fab: Either[A, B])(f: (B, B) => B): Option[B] =
fab.right.toOption
fab.toOption

override def reduceRightOption[B](fab: Either[A, B])(f: (B, Eval[B]) => Eval[B]): Eval[Option[B]] =
Now(fab.right.toOption)
Now(fab.toOption)

override def size[B](fab: Either[A, B]): Long =
fab.fold(_ => 0L, _ => 1L)
Expand All @@ -129,10 +129,10 @@ trait EitherInstances extends cats.kernel.instances.EitherInstances {
fab.fold(_ => None, r => if (f(r)) Some(r) else None)

override def exists[B](fab: Either[A, B])(p: B => Boolean): Boolean =
fab.right.exists(p)
fab.exists(p)

override def forall[B](fab: Either[A, B])(p: B => Boolean): Boolean =
fab.right.forall(p)
fab.forall(p)

override def toList[B](fab: Either[A, B]): List[B] =
fab.fold(_ => Nil, _ :: Nil)
Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/cats/instances/parallel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import cats.syntax.either._
import cats.{~>, Applicative, Apply, FlatMap, Functor, Monad, NonEmptyParallel, Parallel}
import kernel.compat.scalaVersionSpecific._

@suppressUnusedImportWarningForScalaVersionSpecific
trait ParallelInstances extends ParallelInstances1 {
implicit def catsParallelForEitherValidated[E: Semigroup]: Parallel[Either[E, ?], Validated[E, ?]] =
new Parallel[Either[E, ?], Validated[E, ?]] {
Expand Down
10 changes: 4 additions & 6 deletions free/src/main/scala/cats/free/FreeApplicative.scala
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,10 @@ object FreeApplicative {

// Internal helper function for foldMap, it folds only Pure and Lift nodes
private[free] def foldArg[F[_], G[_], A](node: FA[F, A], f: F ~> G)(implicit G: Applicative[G]): G[A] =
if (node.isInstanceOf[Pure[F, A]]) {
val Pure(x) = node
G.pure(x)
} else {
val Lift(fa) = node
f(fa)
node match {
case Pure(x) => G.pure(x)
case Lift(fa) => f(fa)
case x => throw new RuntimeException(s"Impossible for a $x to reach here")
}

/** Represents a curried function `F[A => B => C => ...]`
Expand Down
Loading