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

Fix obvious and straightforward warnings #4323

Merged
merged 7 commits into from
Oct 27, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ object Rules {
}

def collect0[A: Arbitrary: Eq](name: String, sym: String, id: A)(c: Seq[A] => A): (String, Prop) =
s"$name(Nil) == $sym" -> forAll { (a: A) =>
s"$name(Nil) == $sym" -> forAll { (_: A) =>
c(Nil) ?== id
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala-2.13+/cats/instances/lazyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ trait LazyListInstances extends cats.kernel.instances.LazyListInstances {

override def find[A](fa: LazyList[A])(f: A => Boolean): Option[A] = fa.find(f)

override def algebra[A]: Monoid[LazyList[A]] = new kernel.instances.LazyListMonoid[A]
override def algebra[A]: Monoid[LazyList[A]] = kernel.instances.LazyListMonoid[A]

override def collectFirst[A, B](fa: LazyList[A])(pf: PartialFunction[A, B]): Option[B] = fa.collectFirst(pf)

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala-2.13+/cats/instances/stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ trait StreamInstances extends cats.kernel.instances.StreamInstances {
case Left(a) #:: tail =>
stack = fn(a) #::: tail
advance()
case empty =>
case _ => // empty
state = Right(None)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
package cats
package arrow

import scala.language.experimental.macros
import scala.reflect.macros.blackbox

private[arrow] class FunctionKMacroMethods {
Expand Down
6 changes: 2 additions & 4 deletions core/src/main/scala/cats/data/EitherT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,6 @@ abstract private[data] class EitherTInstances extends EitherTInstances1 {
type F[x] = Nested[P.F, Validated[E, *], x]

implicit val monadM: Monad[M] = P.monad
implicit val monadEither: Monad[Either[E, *]] = cats.instances.either.catsStdInstancesForEither

def applicative: Applicative[Nested[P.F, Validated[E, *], *]] =
cats.data.Nested.catsDataApplicativeForNested(P.applicative, Validated.catsDataApplicativeErrorForValidated)
Expand Down Expand Up @@ -1115,7 +1114,6 @@ abstract private[data] class EitherTInstances1 extends EitherTInstances2 {
type F[x] = Nested[M, Validated[E, *], x]

implicit val appValidated: Applicative[Validated[E, *]] = Validated.catsDataApplicativeErrorForValidated
implicit val monadEither: Monad[Either[E, *]] = cats.instances.either.catsStdInstancesForEither

def applicative: Applicative[Nested[M, Validated[E, *], *]] =
cats.data.Nested.catsDataApplicativeForNested[M, Validated[E, *]]
Expand Down Expand Up @@ -1187,14 +1185,14 @@ private[data] trait EitherTSemigroupK[F[_], L] extends SemigroupK[EitherT[F, L,
implicit val F: Monad[F]
def combineK[A](x: EitherT[F, L, A], y: EitherT[F, L, A]): EitherT[F, L, A] =
EitherT(F.flatMap(x.value) {
case l @ Left(_) => y.value
case r @ Right(_) => F.pure(r)
case Left(_) => y.value
})

override def combineKEval[A](x: EitherT[F, L, A], y: Eval[EitherT[F, L, A]]): Eval[EitherT[F, L, A]] =
Eval.now(EitherT(F.flatMap(x.value) {
case l @ Left(_) => y.value.value
case r @ Right(_) => F.pure(r: Either[L, A])
case Left(_) => y.value.value
}))
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/data/Func.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ sealed private[data] trait FuncApply[F[_], C] extends Apply[λ[α => Func[F, C,
sealed private[data] trait FuncApplicative[F[_], C] extends Applicative[λ[α => Func[F, C, α]]] with FuncApply[F, C] {
def F: Applicative[F]
def pure[A](a: A): Func[F, C, A] =
Func.func(c => F.pure(a))
Func.func(Function.const(F.pure(a)))
}

/**
Expand Down Expand Up @@ -167,5 +167,5 @@ sealed private[data] trait AppFuncApplicative[F[_], C] extends Applicative[λ[α
override def product[A, B](fa: AppFunc[F, C, A], fb: AppFunc[F, C, B]): AppFunc[F, C, (A, B)] =
Func.appFunc[F, C, (A, B)](c => F.product(fa.run(c), fb.run(c)))(F)
def pure[A](a: A): AppFunc[F, C, A] =
Func.appFunc[F, C, A](c => F.pure(a))(F)
Func.appFunc[F, C, A](Function.const(F.pure(a)))(F)
}
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/data/IndexedReaderWriterStateT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ final class IndexedReaderWriterStateT[F[_], E, L, SA, SB, A](val runF: F[(E, SA)
* Inspect a value from the input state, without modifying the state.
*/
def inspect[B](f: SB => B)(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, L, SA, SB, B] =
transform { (l, sb, a) =>
transform { (l, sb, _) =>
(l, sb, f(sb))
}

Expand Down Expand Up @@ -287,7 +287,7 @@ final class IndexedReaderWriterStateT[F[_], E, L, SA, SB, A](val runF: F[(E, SA)
* Retrieve the value written to the log.
*/
def written(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, L, SA, SB, L] =
transform { (l, sb, a) =>
transform { (l, sb, _) =>
(l, sb, l)
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/data/IndexedStateT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ sealed abstract private[data] class IndexedStateTContravariantMonoidal[F[_], S]
implicit def F: ContravariantMonoidal[F]
implicit def G: Applicative[F]

override def unit: IndexedStateT[F, S, S, Unit] =
IndexedStateT.applyF(G.pure((s: S) => F.trivial[(S, Unit)]))
override val unit: IndexedStateT[F, S, S, Unit] =
IndexedStateT.applyF(G.pure((_: S) => F.trivial[(S, Unit)]))

override def contramap[A, B](fa: IndexedStateT[F, S, S, A])(f: B => A): IndexedStateT[F, S, S, B] =
contramap2(fa, trivial)(((a: A) => (a, a)).compose(f))
Expand Down
15 changes: 8 additions & 7 deletions core/src/main/scala/cats/data/Ior.scala
Original file line number Diff line number Diff line change
Expand Up @@ -793,11 +793,12 @@ sealed abstract class Ior[+A, +B] extends Product with Serializable {
}

final def ===[AA >: A, BB >: B](that: AA Ior BB)(implicit AA: Eq[AA], BB: Eq[BB]): Boolean =
fold(
a => that.fold(a2 => AA.eqv(a, a2), b2 => false, (a2, b2) => false),
b => that.fold(a2 => false, b2 => BB.eqv(b, b2), (a2, b2) => false),
(a, b) => that.fold(a2 => false, b2 => false, (a2, b2) => AA.eqv(a, a2) && BB.eqv(b, b2))
)
(this, that) match {
case (Ior.Left(a), Ior.Left(aa)) => AA.eqv(a, aa)
case (Ior.Right(b), Ior.Right(bb)) => BB.eqv(b, bb)
case (Ior.Both(a, b), Ior.Both(aa, bb)) => AA.eqv(a, aa) && BB.eqv(b, bb)
case _ => false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we are going to discourage using case _ then should I change it to case (_, _) => or something?

Copy link
Member

@danicheg danicheg Oct 20, 2022

Choose a reason for hiding this comment

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

uh oh, here we have 3! cases to match. probably a wildcard case is a trade-off here. (_, _) is fine with me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the wildcard should be fine here – since we construct the tuple in-place then it won't cause any additional value uncertainty like null values or something...

}

final def compare[AA >: A, BB >: B](that: AA Ior BB)(implicit AA: Order[AA], BB: Order[BB]): Int =
(this, that) match {
Expand Down Expand Up @@ -938,9 +939,9 @@ sealed abstract private[data] class IorInstances extends IorInstances0 {
}
case Ior.Left(e1) =>
ff match {
case Ior.Right(f) => Ior.Left(e1)
case Ior.Both(e2, f) => Ior.Left(E.combine(e2, e1))
case Ior.Left(e2) => Ior.Left(E.combine(e2, e1))
case Ior.Both(e2, _) => Ior.Left(E.combine(e2, e1))
case Ior.Right(_) => Ior.Left(e1)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/Validated.scala
Original file line number Diff line number Diff line change
Expand Up @@ -908,8 +908,8 @@ sealed abstract private[data] class ValidatedInstances extends ValidatedInstance
}
case Valid(a) =>
fb match {
case Invalid(e) => Valid(f(Ior.left(a)))
case Valid(b) => Valid(f(Ior.both(a, b)))
case Invalid(_) => Valid(f(Ior.left(a)))
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/scala/cats/instances/either.scala
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@ trait EitherInstances extends cats.kernel.instances.EitherInstances {

override def alignWith[B, C, D](fb: Either[A, B], fc: Either[A, C])(f: Ior[B, C] => D): Either[A, D] =
fb match {
case left @ Left(a) =>
fc match {
case Left(_) => left.rightCast[D]
case Right(c) => Right(f(Ior.right(c)))
}
case Right(b) =>
fc match {
case Left(a) => Right(f(Ior.left(b)))
case Right(c) => Right(f(Ior.both(b, c)))
case Left(_) => Right(f(Ior.left(b)))
}
case left @ Left(_) =>
fc match {
case Right(c) => Right(f(Ior.right(c)))
case Left(_) => left.rightCast[D]
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/instances/list.scala
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ trait ListInstances extends cats.kernel.instances.ListInstances {

override def dropWhile_[A](fa: List[A])(p: A => Boolean): List[A] = fa.dropWhile(p)

override def algebra[A]: Monoid[List[A]] = new kernel.instances.ListMonoid[A]
override def algebra[A]: Monoid[List[A]] = kernel.instances.ListMonoid[A]

override def collectFirst[A, B](fa: List[A])(pf: PartialFunction[A, B]): Option[B] = fa.collectFirst(pf)

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/instances/map.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ trait MapInstances extends cats.kernel.instances.MapInstances {
def flatMap[A, B](fa: Map[K, A])(f: (A) => Map[K, B]): Map[K, B] =
fa.flatMap { case (k, a) => f(a).get(k).map((k, _)) }

def unorderedFoldMap[A, B: CommutativeMonoid](fa: Map[K, A])(f: (A) => B) =
fa.foldLeft(Monoid[B].empty) { case (b, (k, a)) => Monoid[B].combine(b, f(a)) }
def unorderedFoldMap[A, B: CommutativeMonoid](fa: Map[K, A])(f: A => B): B =
Monoid[B].combineAll(fa.valuesIterator.map(f))

def tailRecM[A, B](a: A)(f: A => Map[K, Either[A, B]]): Map[K, B] = {
val bldr = Map.newBuilder[K, B]
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/instances/queue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ trait QueueInstances extends cats.kernel.instances.QueueInstances {
fa.iterator.dropWhile(p).toList

override def algebra[A]: Monoid[Queue[A]] =
new kernel.instances.QueueMonoid[A]
kernel.instances.QueueMonoid[A]

override def collectFirst[A, B](fa: Queue[A])(pf: PartialFunction[A, B]): Option[B] = fa.collectFirst(pf)

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/instances/seq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ trait SeqInstances extends cats.kernel.instances.SeqInstances {

override def find[A](fa: Seq[A])(f: A => Boolean): Option[A] = fa.find(f)

override def algebra[A]: Monoid[Seq[A]] = new kernel.instances.SeqMonoid[A]
override def algebra[A]: Monoid[Seq[A]] = kernel.instances.SeqMonoid[A]

def functor: Functor[Seq] = this

Expand Down
7 changes: 2 additions & 5 deletions core/src/main/scala/cats/instances/sortedMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ trait SortedMapInstances extends SortedMapInstances2 {

def tailRecM[A, B](a: A)(f: A => SortedMap[K, Either[A, B]]): SortedMap[K, B] = {
val fa = f(a)
var bldr = SortedMap.newBuilder[K, B](fa.ordering)
val bldr = SortedMap.newBuilder[K, B](fa.ordering)

@tailrec def descend(k: K, either: Either[A, B]): Unit =
either match {
Expand Down Expand Up @@ -204,10 +204,7 @@ class SortedMapEq[K, V](implicit V: Eq[V], O: Order[K]) extends cats.kernel.inst
@deprecated("Use cats.kernel.instances.SortedMapCommutativeMonoid", "2.0.0-RC2")
class SortedMapCommutativeMonoid[K, V](implicit V: CommutativeSemigroup[V], O: Order[K])
extends SortedMapMonoid[K, V]
with CommutativeMonoid[SortedMap[K, V]] {
private[this] val underlying: CommutativeMonoid[SortedMap[K, V]] =
new cats.kernel.instances.SortedMapCommutativeMonoid[K, V]
}
with CommutativeMonoid[SortedMap[K, V]]

@deprecated("Use cats.kernel.instances.SortedMapMonoid", "2.0.0-RC2")
class SortedMapMonoid[K, V](implicit V: Semigroup[V], O: Order[K]) extends cats.kernel.instances.SortedMapMonoid[K, V]
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/instances/vector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ trait VectorInstances extends cats.kernel.instances.VectorInstances {

override def find[A](fa: Vector[A])(f: A => Boolean): Option[A] = fa.find(f)

override def algebra[A]: Monoid[Vector[A]] = new kernel.instances.VectorMonoid[A]
override def algebra[A]: Monoid[Vector[A]] = kernel.instances.VectorMonoid[A]

def functor: Functor[Vector] = this

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object SerializableLaws {
oos.close()
val bais = new ByteArrayInputStream(baos.toByteArray())
ois = new ObjectInputStream(bais)
val a2 = ois.readObject()
val _ = ois.readObject()
ois.close()
Result(status = Proof)
} catch {
Expand Down
2 changes: 1 addition & 1 deletion laws/src/main/scala/cats/laws/ApplicativeErrorLaws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ trait ApplicativeErrorLaws[F[_], E] extends ApplicativeLaws[F] {
F.onError(F.pure(a)) { case x => f(x) } <-> F.pure(a)

def onErrorRaise[A](fa: F[A], e: E, fb: F[Unit]): IsEq[F[A]] =
F.onError(F.raiseError[A](e)) { case err => fb } <-> F.map2(fb, F.raiseError[A](e))((_, b) => b)
F.onError(F.raiseError[A](e)) { case _ => fb } <-> F.map2(fb, F.raiseError[A](e))((_, b) => b)

def adaptErrorPure[A](a: A, f: E => E): IsEq[F[A]] =
F.adaptError(F.pure(a)) { case x => f(x) } <-> F.pure(a)
Expand Down
2 changes: 1 addition & 1 deletion laws/src/main/scala/cats/laws/DeferLaws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trait DeferLaws[F[_]] {

def deferDoesNotEvaluate[A](fa: Unit => F[A]): IsEq[Boolean] = {
var evaluated = false
val deferUnit = F.defer {
val _ = F.defer {
evaluated = true;
fa(())
}
Expand Down
4 changes: 2 additions & 2 deletions laws/src/main/scala/cats/laws/ShortCircuitingLaws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trait ShortCircuitingLaws[F[_]] {
def foldMapKShortCircuits[A](fa: F[A], empty: A)(implicit F: Foldable[F]): IsEq[Long] = {
val size = fa.size
val maxInvocationsAllowed = size / 2
val f = new RestrictedFunction[A, Option[A]]((a: A) => None, maxInvocationsAllowed, Some(empty))
val f = new RestrictedFunction[A, Option[A]](Function.const(None), maxInvocationsAllowed, Some(empty))

fa.foldMapK(f)
f.invocations.get <-> (maxInvocationsAllowed + 1).min(size)
Expand All @@ -44,7 +44,7 @@ trait ShortCircuitingLaws[F[_]] {
def foldMapKWontShortCircuit[A](fa: F[A], empty: A)(implicit F: Foldable[F]): IsEq[Long] = {
val size = fa.size
val maxInvocationsAllowed = size / 2
val f = new RestrictedFunction[A, Option[A]]((a: A) => None, maxInvocationsAllowed, Some(empty))
val f = new RestrictedFunction[A, Option[A]](Function.const(None), maxInvocationsAllowed, Some(empty))

fa.foldMapK(f)(F, nonShortCircuitingMonoidK)
f.invocations.get <-> size
Expand Down