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 more warnings on 2.13 #2911

Merged
merged 3 commits into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:

- env: TEST="docs"
install: gem install jekyll -v 2.5
script: sbt makeMicrosite
script: sbt docs/makeMicrosite

- stage: styling
env: TEST="linting"
Expand Down
27 changes: 17 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ def scalaVersionSpecificFolders(srcName: String, srcBaseDir: java.io.File, scala
case _ => Nil
}
}

lazy val commonScalaVersionSettings = Seq(
crossScalaVersions := (crossScalaVersionsFromTravis in Global).value,
scalaVersion := crossScalaVersions.value.find(_.contains("2.12")).get
scalaVersion := crossScalaVersions.value.find(_.contains("2.13")).get
)

commonScalaVersionSettings

lazy val commonSettings = commonScalaVersionSettings ++ Seq(
scalacOptions ++= commonScalacOptions(scalaVersion.value),
Compile / unmanagedSourceDirectories ++= scalaVersionSpecificFolders("main", baseDirectory.value, scalaVersion.value),
Expand Down Expand Up @@ -407,7 +410,7 @@ lazy val docs = project
.settings(catsSettings)
.settings(noPublishSettings)
.settings(docSettings)
.settings(commonJvmSettings)
.settings(commonJvmSettings, scalaVersion := "2.12.8") // temporarily fix the version to 2.12 due to https://github.com/47deg/sbt-microsites/issues/305
.dependsOn(core.jvm, free.jvm, kernelLaws.jvm, laws.jvm, testkit.jvm)

lazy val cats = project
Expand Down Expand Up @@ -435,8 +438,8 @@ lazy val catsJVM = project
alleycatsCore.jvm,
alleycatsLaws.jvm,
alleycatsTests.jvm,
jvm,
docs)
jvm)
//docs) Temporarily disable docs from aggregating because of https://github.com/47deg/sbt-microsites/issues/305 and I would like to set the default scala version to 2.13
.dependsOn(
macros.jvm,
kernel.jvm,
Expand Down Expand Up @@ -626,11 +629,15 @@ lazy val bench = project
.settings(commonJvmSettings)
.settings(coverageEnabled := false)
.settings(
libraryDependencies ++= Seq(
"org.scalaz" %% "scalaz-core" % "7.2.23",
"org.spire-math" %% "chain" % "0.3.0",
"co.fs2" %% "fs2-core" % "0.10.4"
)
libraryDependencies ++= {
if (priorTo2_13(scalaVersion.value))
Seq(
"org.scalaz" %% "scalaz-core" % "7.2.23",
"org.spire-math" %% "chain" % "0.3.0",
"co.fs2" %% "fs2-core" % "0.10.4"
)
else Nil
}
)
.enablePlugins(JmhPlugin)

Expand All @@ -645,7 +652,7 @@ lazy val binCompatTest = project
if (priorTo2_13(scalaVersion.value))
mimaPrevious("cats-core", scalaVersion.value, version.value).last % Provided
else //We are not testing BC on Scala 2.13 yet.
"org.typelevel" %% "cats-core" % version.value % Provided
"org.typelevel" %% "cats-core" % "2.0.0-M4" % Provided
},
"org.scalatest" %%% "scalatest" % scalatestVersion % Test
)
Expand Down
25 changes: 13 additions & 12 deletions core/src/main/scala-2.13+/cats/instances/lazyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ trait StreamInstances extends LazyListInstances {

trait LazyListInstances extends cats.kernel.instances.StreamInstances {
implicit val catsStdInstancesForLazyList
: Traverse[LazyList] with Alternative[LazyList] with Monad[LazyList] with CoflatMap[LazyList] =
: Traverse[LazyList] with Alternative[LazyList] with Monad[LazyList] with CoflatMap[LazyList] =
new Traverse[LazyList] with Alternative[LazyList] with Monad[LazyList] with CoflatMap[LazyList] {

def empty[A]: LazyList[A] = LazyList.empty

def combineK[A](x: LazyList[A], y: LazyList[A]): LazyList[A] = x lazyAppendedAll y
def combineK[A](x: LazyList[A], y: LazyList[A]): LazyList[A] = x.lazyAppendedAll(y)

def pure[A](x: A): LazyList[A] = LazyList(x)

Expand Down Expand Up @@ -55,9 +55,9 @@ trait LazyListInstances extends cats.kernel.instances.StreamInstances {
B.combineAll(fa.iterator.map(f))

def traverse[G[_], A, B](fa: LazyList[A])(f: A => G[B])(implicit G: Applicative[G]): G[LazyList[B]] =
// We use foldRight to avoid possible stack overflows. Since
// we don't want to return a Eval[_] instance, we call .value
// at the end.
// We use foldRight to avoid possible stack overflows. Since
// we don't want to return a Eval[_] instance, we call .value
// at the end.
foldRight(fa, Always(G.pure(LazyList.empty[B]))) { (a, lgsb) =>
G.map2Eval(f(a), lgsb)(_ #:: _)
}.value
Expand Down Expand Up @@ -85,8 +85,7 @@ trait LazyListInstances extends cats.kernel.instances.StreamInstances {
stack = nextFront :: stack
advance()
}
}
else {
} else {
stack = tail
advance()
}
Expand Down Expand Up @@ -190,16 +189,18 @@ trait LazyListInstances extends cats.kernel.instances.StreamInstances {

override def flattenOption[A](fa: LazyList[Option[A]]): LazyList[A] = fa.flatten

def traverseFilter[G[_], A, B](fa: LazyList[A])(f: (A) => G[Option[B]])(implicit G: Applicative[G]): G[LazyList[B]] =
def traverseFilter[G[_], A, B](
fa: LazyList[A]
)(f: (A) => G[Option[B]])(implicit G: Applicative[G]): G[LazyList[B]] =
fa.foldRight(Eval.now(G.pure(LazyList.empty[B])))(
(x, xse) => G.map2Eval(f(x), xse)((i, o) => i.fold(o)(_ +: o))
)
(x, xse) => G.map2Eval(f(x), xse)((i, o) => i.fold(o)(_ +: o))
)
.value

override def filterA[G[_], A](fa: LazyList[A])(f: (A) => G[Boolean])(implicit G: Applicative[G]): G[LazyList[A]] =
fa.foldRight(Eval.now(G.pure(LazyList.empty[A])))(
(x, xse) => G.map2Eval(f(x), xse)((b, as) => if (b) x +: as else as)
)
(x, xse) => G.map2Eval(f(x), xse)((b, as) => if (b) x +: as else as)
)
.value

}
Expand Down
29 changes: 15 additions & 14 deletions core/src/main/scala/cats/Invariant.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cats

import cats.kernel._
import simulacrum.typeclass
import cats.kernel.compat.scalaVersionSpecific._

/**
* Must obey the laws defined in cats.laws.InvariantLaws.
Expand Down Expand Up @@ -49,8 +50,8 @@ object Invariant {
def imap[A, B](fa: Monoid[A])(f: A => B)(g: B => A): Monoid[B] = new Monoid[B] {
val empty = f(fa.empty)
def combine(x: B, y: B): B = f(fa.combine(g(x), g(y)))
override def combineAllOption(bs: TraversableOnce[B]): Option[B] =
fa.combineAllOption(bs.map(g)).map(f)
override def combineAllOption(bs: IterableOnce[B]): Option[B] =
fa.combineAllOption(bs.iterator.map(g)).map(f)
}

}
Expand All @@ -59,17 +60,17 @@ object Invariant {

def imap[A, B](fa: Band[A])(f: A => B)(g: B => A): Band[B] = new Band[B] {
def combine(x: B, y: B): B = f(fa.combine(g(x), g(y)))
override def combineAllOption(bs: TraversableOnce[B]): Option[B] =
fa.combineAllOption(bs.map(g)).map(f)
override def combineAllOption(bs: IterableOnce[B]): Option[B] =
fa.combineAllOption(bs.iterator.map(g)).map(f)
}
}

implicit val catsInvariantSemilattice: Invariant[Semilattice] = new Invariant[Semilattice] {

def imap[A, B](fa: Semilattice[A])(f: A => B)(g: B => A): Semilattice[B] = new Semilattice[B] {
def combine(x: B, y: B): B = f(fa.combine(g(x), g(y)))
override def combineAllOption(bs: TraversableOnce[B]): Option[B] =
fa.combineAllOption(bs.map(g)).map(f)
override def combineAllOption(bs: IterableOnce[B]): Option[B] =
fa.combineAllOption(bs.iterator.map(g)).map(f)
}

}
Expand All @@ -79,8 +80,8 @@ object Invariant {
def imap[A, B](fa: CommutativeMonoid[A])(f: A => B)(g: B => A): CommutativeMonoid[B] = new CommutativeMonoid[B] {
val empty = f(fa.empty)
def combine(x: B, y: B): B = f(fa.combine(g(x), g(y)))
override def combineAllOption(bs: TraversableOnce[B]): Option[B] =
fa.combineAllOption(bs.map(g)).map(f)
override def combineAllOption(bs: IterableOnce[B]): Option[B] =
fa.combineAllOption(bs.iterator.map(g)).map(f)
}

}
Expand All @@ -90,8 +91,8 @@ object Invariant {
def imap[A, B](fa: BoundedSemilattice[A])(f: A => B)(g: B => A): BoundedSemilattice[B] = new BoundedSemilattice[B] {
val empty = f(fa.empty)
def combine(x: B, y: B): B = f(fa.combine(g(x), g(y)))
override def combineAllOption(bs: TraversableOnce[B]): Option[B] =
fa.combineAllOption(bs.map(g)).map(f)
override def combineAllOption(bs: IterableOnce[B]): Option[B] =
fa.combineAllOption(bs.iterator.map(g)).map(f)
}

}
Expand All @@ -102,8 +103,8 @@ object Invariant {
val empty = f(fa.empty)
def combine(x: B, y: B): B = f(fa.combine(g(x), g(y)))
def inverse(b: B): B = f(fa.inverse(g(b)))
override def combineAllOption(bs: TraversableOnce[B]): Option[B] =
fa.combineAllOption(bs.map(g)).map(f)
override def combineAllOption(bs: IterableOnce[B]): Option[B] =
fa.combineAllOption(bs.iterator.map(g)).map(f)
}

}
Expand All @@ -114,8 +115,8 @@ object Invariant {
val empty = f(fa.empty)
def combine(x: B, y: B): B = f(fa.combine(g(x), g(y)))
def inverse(b: B): B = f(fa.inverse(g(b)))
override def combineAllOption(bs: TraversableOnce[B]): Option[B] =
fa.combineAllOption(bs.map(g)).map(f)
override def combineAllOption(bs: IterableOnce[B]): Option[B] =
fa.combineAllOption(bs.iterator.map(g)).map(f)
}

}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/OneAnd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package data
import scala.annotation.tailrec
import scala.collection.mutable.Builder
import cats.instances.stream._
import kernel.compat.lazyList._
import kernel.compat.scalaVersionSpecific._

/**
* A data type which represents a single element (head) and some other
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/ZipStream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cats
package data

import instances.stream._
import kernel.compat.lazyList._
import kernel.compat.scalaVersionSpecific._

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

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/package.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package cats
import kernel.compat.lazyList._
import kernel.compat.scalaVersionSpecific._
import compat.lazyList.toLazyList
package object data {

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/instances/parallel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cats.data._
import cats.kernel.Semigroup
import cats.syntax.either._
import cats.{~>, Applicative, Apply, FlatMap, Functor, Monad, NonEmptyParallel, Parallel}
import kernel.compat.lazyList._
import kernel.compat.scalaVersionSpecific._

trait ParallelInstances extends ParallelInstances1 {
implicit def catsParallelForEitherValidated[E: Semigroup]: Parallel[Either[E, ?], Validated[E, ?]] =
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/instances/set.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ trait SetInstances extends cats.kernel.instances.SetInstances {

implicit def catsStdShowForSet[A: Show]: Show[Set[A]] = new Show[Set[A]] {
def show(fa: Set[A]): String =
fa.toIterator.map(_.show).mkString("Set(", ", ", ")")
fa.iterator.map(_.show).mkString("Set(", ", ", ")")
}
}
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/instances/sortedSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ trait SortedSetInstances extends SortedSetInstances1 {
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: SortedSet[A]): Long = fa.size.toLong
Expand Down Expand Up @@ -64,7 +64,7 @@ trait SortedSetInstances extends SortedSetInstances1 {

implicit def catsStdShowForSortedSet[A: Show]: Show[SortedSet[A]] = new Show[SortedSet[A]] {
def show(fa: SortedSet[A]): String =
fa.toIterator.map(_.show).mkString("SortedSet(", ", ", ")")
fa.iterator.map(_.show).mkString("SortedSet(", ", ", ")")
}

implicit def catsKernelStdOrderForSortedSet[A: Order]: Order[SortedSet[A]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.scalatest.funsuite.AnyFunSuiteLike
import scala.concurrent.duration.{Duration, FiniteDuration}
import scala.collection.immutable.{BitSet, Queue}
import scala.util.Random
import compat.lazyList._
import compat.scalaVersionSpecific._
import java.util.UUID
import java.util.concurrent.TimeUnit.{DAYS, HOURS, MICROSECONDS, MILLISECONDS, MINUTES, NANOSECONDS, SECONDS}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cats.kernel
package compat

@deprecated("No longer needed. Kept for bin compat", "2.0.0-RC1")
private[kernel] object TraversableOnce {
def reduceOption[A, A1 >: A](as: TraversableOnce[A], op: (A1, A1) => A1): Option[A1] =
as.reduceOption(op)
Expand Down
6 changes: 0 additions & 6 deletions kernel/src/main/scala-2.12-/cats/kernel/compat/lazyList.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package cats.kernel.compat

private[cats] object scalaVersionSpecific {
type LazyList[+A] = Stream[A]
val LazyList = Stream
type IterableOnce[+A] = TraversableOnce[A]

implicit class traversableOnceExtension[A](private val to: TraversableOnce[A]) extends AnyVal {
def iterator: Iterator[A] = to.toIterator
}
}

This file was deleted.

9 changes: 0 additions & 9 deletions kernel/src/main/scala-2.13+/cats/kernel/compat/lazyList.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cats
package kernel

package compat

private[cats] object scalaVersionSpecific {
type LazyList[+A] = scala.LazyList[A] //this is needed only to avoid unused import warnings on Scala 2.13
type IterableOnce[+A] = scala.IterableOnce[A] //this is needed only to avoid unused import warnings on Scala 2.13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Burn it all down.


implicit class iterableOnceExtension[A](private val io: IterableOnce[A]) extends AnyVal {
def reduceOption(f: (A, A) => A): Option[A] = io.iterator.reduceOption(f)
}
}
5 changes: 3 additions & 2 deletions kernel/src/main/scala/cats/kernel/Eq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cats.kernel
import scala.{specialized => sp}

import scala.math.Equiv
import compat.scalaVersionSpecific._

/**
* A type class used to determine equality between 2 instances of the same
Expand Down Expand Up @@ -110,7 +111,7 @@ object Eq extends EqFunctions[Eq] with EqToEquivConversion {
def allEqualBoundedSemilattice[A]: BoundedSemilattice[Eq[A]] = new BoundedSemilattice[Eq[A]] {
def empty = allEqual[A]
def combine(e1: Eq[A], e2: Eq[A]): Eq[A] = Eq.and(e1, e2)
override def combineAllOption(es: TraversableOnce[Eq[A]]): Option[Eq[A]] =
override def combineAllOption(es: IterableOnce[Eq[A]]): Option[Eq[A]] =
if (es.isEmpty) None
else {
val materialized = es.toVector
Expand All @@ -126,7 +127,7 @@ object Eq extends EqFunctions[Eq] with EqToEquivConversion {
*/
def anyEqualSemilattice[A]: Semilattice[Eq[A]] = new Semilattice[Eq[A]] {
def combine(e1: Eq[A], e2: Eq[A]): Eq[A] = Eq.or(e1, e2)
override def combineAllOption(es: TraversableOnce[Eq[A]]): Option[Eq[A]] =
override def combineAllOption(es: IterableOnce[Eq[A]]): Option[Eq[A]] =
if (es.isEmpty) None
else {
val materialized = es.toVector
Expand Down
Loading