Skip to content

Commit

Permalink
Enable scalac linting / fatal warnings and fix all warnings. (#1373)
Browse files Browse the repository at this point in the history
Also remove a couple unused constraints.

from jbgi/scalac-options
  • Loading branch information
S11001001 committed Oct 28, 2017
2 parents 31e16ce + fbae192 commit f127e47
Show file tree
Hide file tree
Showing 48 changed files with 147 additions and 129 deletions.
8 changes: 7 additions & 1 deletion build.sbt
Expand Up @@ -71,6 +71,7 @@ lazy val concurrent = Project(
base = file("concurrent"),
settings = standardSettings ++ Seq(
name := ConcurrentName,
scalacOptions in (Compile, compile) += "-Xfatal-warnings",
typeClasses := TypeClass.concurrent,
osgiExport("scalaz.concurrent"),
OsgiKeys.importPackage := Seq("javax.swing;resolution:=optional", "*")
Expand All @@ -94,6 +95,8 @@ lazy val example = Project(
name := "scalaz-example",
publishArtifact := false
)
).settings(
scalacOptions in (Compile, compile) -= "-Yno-adapted-args"
)

lazy val scalacheckBinding =
Expand All @@ -102,8 +105,11 @@ lazy val scalacheckBinding =
.settings(standardSettings)
.settings(
name := "scalaz-scalacheck-binding",
scalacOptions in (Compile, compile) += "-Xfatal-warnings",
scalacOptions in (Compile, compile) -= "-Ywarn-value-discard",
libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalaCheckVersion.value,
osgiExport("scalaz.scalacheck"))
osgiExport("scalaz.scalacheck")
)
.dependsOn(core, iteratee)
.jvmConfigure(_ dependsOn concurrent)
.jsSettings(scalajsProjectSettings)
Expand Down
4 changes: 2 additions & 2 deletions concurrent/src/main/scala/scalaz/concurrent/Actor.scala
Expand Up @@ -41,7 +41,7 @@ final case class Actor[A](handler: A => Unit, onError: Throwable => Unit = Actor

def contramap[B](f: B => A): Actor[B] = new Actor[B](b => this ! f(b), onError)(strategy)

private def schedule(n: Node[A]): Unit = strategy(act(n))
private def schedule(n: Node[A]) = { val _ = strategy(act(n)) }

@annotation.tailrec
private def act(n: Node[A], i: Int = 1024): Unit = {
Expand All @@ -54,7 +54,7 @@ final case class Actor[A](handler: A => Unit, onError: Throwable => Unit = Actor
else act(n2, i - 1)
}

private def scheduleLastTry(n: Node[A]): Unit = strategy(lastTry(n))
private def scheduleLastTry(n: Node[A]) = { val _ = strategy(lastTry(n)) }

private def lastTry(n: Node[A]): Unit = if (!head.compareAndSet(n, null)) act(next(n))

Expand Down
8 changes: 4 additions & 4 deletions concurrent/src/main/scala/scalaz/concurrent/Future.scala
@@ -1,6 +1,6 @@
package scalaz.concurrent

import java.util.concurrent.{Callable, ConcurrentLinkedQueue, ExecutorService, TimeoutException, ScheduledExecutorService, TimeUnit}
import java.util.concurrent.{ConcurrentLinkedQueue, ExecutorService, TimeoutException, ScheduledExecutorService, TimeUnit}
import java.util.concurrent.atomic.{AtomicInteger, AtomicBoolean, AtomicReference}

import scala.collection.JavaConverters._
Expand Down Expand Up @@ -379,15 +379,15 @@ object Future {

/** Create a `Future` that will evaluate `a` using the given `ExecutorService`. */
def apply[A](a: => A)(implicit pool: ExecutorService = Strategy.DefaultExecutorService): Future[A] = Async { cb =>
pool.submit { new Callable[Unit] { def call = cb(a).run }}
pool.execute { new Runnable { def run = cb(a).run }}
}

/** Create a `Future` that will evaluate `a` after at least the given delay. */
def schedule[A](a: => A, delay: Duration)(implicit pool: ScheduledExecutorService =
Strategy.DefaultTimeoutScheduler): Future[A] =
Async { cb =>
pool.schedule(new Callable[Unit] {
def call = cb(a).run
val _ = pool.schedule(new Runnable {
def run = cb(a).run
}, delay.toMillis, TimeUnit.MILLISECONDS)
}

Expand Down
Expand Up @@ -64,7 +64,9 @@ trait PhasedLatches {
val sync = new QueuedSynchronizer

/** Release the current phase. */
def release = IO { sync releaseShared 1 }
def release = IO {
val _ = sync releaseShared 1
}

/** Await for the specified phase.*/
@throws(classOf[InterruptedException])
Expand Down
2 changes: 1 addition & 1 deletion concurrent/src/main/scala/scalaz/concurrent/Task.scala
Expand Up @@ -392,7 +392,7 @@ object Task {
// food for thought - might be safe to set the interrupt first
// but, this may also kill `cb(e)`
// could have separate AtomicBooleans for each task
cb(e) *> Trampoline.delay { interrupt.set(true); () }
cb(e) *> Trampoline.delay { interrupt.set(true) }
else
Trampoline.done(())
}
Expand Down
2 changes: 1 addition & 1 deletion concurrent/src/main/scala/scalaz/concurrent/Timer.scala
Expand Up @@ -38,7 +38,7 @@ case class Timer(timeoutTickMs: Int = 100, workerName: String = "TimeoutContextW
}
// Should we keep running?
if (continueRunning) {
Thread.sleep(safeTickMs)
Thread.sleep(safeTickMs.toLong)
innerRun()
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/scalaz/Adjunction.scala
Expand Up @@ -73,7 +73,7 @@ abstract class Adjunction[F[_], G[_]](implicit val F: Functor[F], val G: Functor
object Adjunction extends AdjunctionInstances {
type -|[F[_], G[_]] = Adjunction[F, G]

def apply[F[_], G[_]](implicit A: F -| G, F: Functor[F], G: Functor[F]): F -| G = A
def apply[F[_], G[_]](implicit A: F -| G): F -| G = A
}

sealed abstract class AdjunctionInstances {
Expand All @@ -88,7 +88,7 @@ sealed abstract class AdjunctionInstances {

implicit def curryUncurryAdjunction[S]: (S, ?) -| (S => ?) =
new Adjunction[(S, ?), (S => ?)] {
override def leftAdjunct[A, B](a: => A)(f: ((S, A)) => B): S => B = s => f(s, a)
override def leftAdjunct[A, B](a: => A)(f: ((S, A)) => B): S => B = s => f((s, a))
override def rightAdjunct[A, B](a: (S, A))(f: A => S => B): B = f(a._2)(a._1)
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/scalaz/Cord.scala
Expand Up @@ -114,7 +114,7 @@ final case class Cord(self: FingerTree[Int, String]) {
import syntax.foldable._
import Free._
val sb = new StringBuilder(self.measure)
val t = self.traverse_[Trampoline](x => Trampoline.delay(sb ++= x))
val t = self.traverse_[Trampoline](x => Trampoline.delay {val _ = sb ++= x})
t.run
sb.toString
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/scalaz/Dequeue.scala
Expand Up @@ -36,7 +36,7 @@ sealed abstract class Dequeue[A] {
val xsr = reverseNEL(OneAnd(xx, xs))
Just((f, FullDequeue(xsr, bs-1, OneAnd(x, IList.empty), 1)))
}
case FullDequeue(OneAnd(f, ICons(ff, fs)), s, back, bs) => Just(f, FullDequeue(OneAnd(ff, fs), s-1, back, bs))
case FullDequeue(OneAnd(f, ICons(ff, fs)), s, back, bs) => Just((f, FullDequeue(OneAnd(ff, fs), s - 1, back, bs)))
}

/**
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/scalaz/Diev.scala
Expand Up @@ -144,7 +144,7 @@ trait DievImplementation {
}
}

def +(value: A): Diev[A] = this + (value, value)
def +(value: A): Diev[A] = this + ((value, value))

def -(interval: (A, A)): Diev[A] = {
val orderedInterval = fixIntervalOrder(interval)
Expand All @@ -168,7 +168,7 @@ trait DievImplementation {
}
}

def -(value: A): Diev[A] = this - (value, value)
def -(value: A): Diev[A] = this - ((value, value))

def ++(other: Diev[A]): Diev[A] = other.intervals.foldLeft(this: Diev[A])(_ + _)

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/scalaz/Either.scala
Expand Up @@ -128,7 +128,7 @@ sealed abstract class \/[+A, +B] extends Product with Serializable {

/** Run the side-effect on the right of this disjunction. */
def foreach(g: B => Unit): Unit =
bimap(_ => (), g)
fold(_ => (), g)

/** Apply a function in the environment of the right of this disjunction. */
def ap[AA >: A, C](f: => AA \/ (B => C)): (AA \/ C) =
Expand Down Expand Up @@ -377,7 +377,7 @@ object \/ extends DisjunctionInstances {
def fromEither[A, B](e: Either[A, B]): A \/ B =
e fold (left, right)

def fromTryCatchThrowable[T, E <: Throwable](a: => T)(implicit nn: NotNothing[E], ex: ClassTag[E]): E \/ T = try {
def fromTryCatchThrowable[T, E <: Throwable: NotNothing](a: => T)(implicit ex: ClassTag[E]): E \/ T = try {
\/-(a)
} catch {
case e if ex.runtimeClass.isInstance(e) => -\/(e.asInstanceOf[E])
Expand Down
10 changes: 6 additions & 4 deletions core/src/main/scala/scalaz/EitherT.scala
Expand Up @@ -233,9 +233,11 @@ object EitherT extends EitherTInstances {
eitherT(F.point(a))
}

def eitherTU[FAB, AB, A0, B0](fab: FAB)(
implicit u1: Unapply[Functor, FAB]{type A = AB}, u2: Unapply2[Bifunctor, AB]{type A = A0; type B = B0}, l: Leibniz.===[AB, A0 \/ B0])
: EitherT[u1.M, A0, B0] = eitherT(l.subst[u1.M](u1(fab)))
def eitherTU[FAB, AB, A0, B0](fab: FAB)(implicit
u1: Unapply[Functor, FAB]{type A = AB},
@deprecated("scala/bug#5075", "") u2: Unapply2[Bifunctor, AB]{type A = A0; type B = B0},
l: Leibniz.===[AB, A0 \/ B0]
): EitherT[u1.M, A0, B0] = eitherT(l.subst[u1.M](u1(fab)))

def monadTell[F[_], W, A](implicit MT0: MonadTell[F, W]): EitherTMonadTell[F, W, A] = new EitherTMonadTell[F, W, A]{
def MT = MT0
Expand Down Expand Up @@ -279,7 +281,7 @@ object EitherT extends EitherTInstances {
def fromEither[F[_], A, B](e: F[Either[A, B]])(implicit F: Functor[F]): EitherT[F, A, B] =
apply(F.map(e)(_ fold (\/.left, \/.right)))

def fromTryCatchThrowable[F[_], A, B <: Throwable](a: => F[A])(implicit F: Applicative[F], nn: NotNothing[B], ex: ClassTag[B]): EitherT[F, B, A] =
def fromTryCatchThrowable[F[_], A, B <: Throwable: NotNothing](a: => F[A])(implicit F: Applicative[F], ex: ClassTag[B]): EitherT[F, B, A] =
try {
right(a)
} catch {
Expand Down
5 changes: 1 addition & 4 deletions core/src/main/scala/scalaz/FingerTree.scala
Expand Up @@ -449,8 +449,6 @@ sealed abstract class FingerTree[V, A](implicit measurer: Reducer[A, V]) {
private type AFinger = Finger[V, A]
private type NodeTree = FingerTree[V, Node[V, A]]

private implicit def sg: Monoid[V] = measurer.monoid

def add1(n: A, right: => ATree): ATree = {
val rightz = Need(right)
fold(
Expand Down Expand Up @@ -1019,7 +1017,6 @@ object FingerTree extends FingerTreeInstances {
def deep[V, A](v: V, pr: Finger[V, A], m: => FingerTree[V, Node[V, A]], sf: Finger[V, A])
(implicit ms: Reducer[A, V]): FingerTree[V, A] =
new FingerTree[V, A] {
implicit val nMeasure = nodeMeasure[A, V]
private[this] val mz = Need(m)
def fold[B](b: V => B, f: (V, A) => B, d: (V, Finger[V, A], => FingerTree[V, Node[V, A]], Finger[V, A]) => B): B =
d(v, pr, mz.value, sf)
Expand Down Expand Up @@ -1058,7 +1055,7 @@ final class IndSeq[A](val self: FingerTree[Int, A]) {
import std.anyVal._
import IndSeq.indSeq

implicit def sizer[A]: Reducer[A, Int] = UnitReducer((a: A) => 1)
private implicit def sizer[A]: Reducer[A, Int] = UnitReducer((_: A) => 1)
def apply(i: Int): A =
self.split(_ > i)._2.viewl.headOption.getOrElse(sys.error("Index " + i + " > " + self.measure))
def replace(i: Int, a: => A): IndSeq[A] = {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/scalaz/ISet.scala
Expand Up @@ -642,7 +642,6 @@ sealed abstract class ISetInstances {
}

implicit def setOrder[A: Order]: Order[ISet[A]] = new Order[ISet[A]] with ISetEqual[A] {
import std.list._
def A = implicitly

def order(x: ISet[A], y: ISet[A]) =
Expand All @@ -661,6 +660,7 @@ sealed abstract class ISetInstances {
case x :: Nil =>
buf.append(A.shows(x))
buf.append(')')
()
case x :: xs =>
buf.append(A.shows(x))
buf.append(',')
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/scalaz/ImmutableArray.scala
Expand Up @@ -141,7 +141,7 @@ object ImmutableArray extends ImmutableArrayInstances {
def apply: Builder[T, ImmutableArray[T]] = newBuilder(m)
}

implicit def canBuildFromChar(implicit m: ClassTag[Char]): CanBuildFrom[ImmutableArray[_], Char, ImmutableArray[Char]] =
implicit val canBuildFromChar: CanBuildFrom[ImmutableArray[_], Char, ImmutableArray[Char]] =
new CanBuildFrom[ImmutableArray[_], Char, ImmutableArray[Char]] {
def apply(from: ImmutableArray[_]): Builder[Char, ImmutableArray[Char]] = newStringArrayBuilder

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/scalaz/Kleisli.scala
Expand Up @@ -85,7 +85,7 @@ final case class Kleisli[M[_], A, B](run: A => M[B]) { self =>
def endo(implicit M: Functor[M], ev: A >~> B): Endomorphic[Kleisli[M, ?, ?], A] =
Endomorphic[Kleisli[M, ?, ?], A](map(ev.apply))

def liftF(implicit F: Functor[Kleisli[M, A, ?]]): Free[Kleisli[M, A, ?], B] =
def liftF: Free[Kleisli[M, A, ?], B] =
Free.liftF[Kleisli[M, A, ?], B](self)

def tap(implicit F: Applicative[M]): Kleisli[M, A, A] =
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/scalaz/LazyEitherT.scala
Expand Up @@ -105,9 +105,9 @@ object LazyEitherT extends LazyEitherTInstances {
LazyEitherT(a)

def lazyEitherTU[FAB, AB, A0, B0](fab: FAB)(implicit
u1: Unapply[Functor, FAB]{type A = AB},
u2: Unapply2[Bifunctor, AB]{type A = A0; type B = B0},
l: Leibniz.===[AB, LazyEither[A0, B0]]
u1: Unapply[Functor, FAB]{type A = AB},
@deprecated("scala/bug#5075", "") u2: Unapply2[Bifunctor, AB]{type A = A0; type B = B0},
l: Leibniz.===[AB, LazyEither[A0, B0]]
): LazyEitherT[u1.M, A0, B0] = LazyEitherT(l.subst[u1.M](u1(fab)))

import LazyEither._
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/scala/scalaz/Lens.scala
Expand Up @@ -280,8 +280,8 @@ trait LensFamilyFunctions {

def factorLensFamily[A1, A2, B1, B2, C1, C2]: LensFamily[((A1, B1) \/ (A1, C1)), ((A2, B2) \/ (A2, C2)), (A1, B1 \/ C1), (A2, B2 \/ C2)] =
lensFamily(e => IndexedStore({
case (a, -\/(b)) => -\/(a, b)
case (a, \/-(c)) => \/-(a, c)
case (a, -\/(b)) => -\/((a, b))
case (a, \/-(c)) => \/-((a, c))
}, e match {
case -\/((a, b)) => (a, -\/(b))
case \/-((a, c)) => (a, \/-(c))
Expand All @@ -293,8 +293,8 @@ trait LensFamilyFunctions {
case -\/((aa, bb)) => (aa, -\/(bb))
case \/-((aa, cc)) => (aa, \/-(cc))
}, e match {
case -\/(b) => -\/(a, b)
case \/-(c) => \/-(a, c)
case -\/(b) => -\/((a, b))
case \/-(c) => \/-((a, c))

})
}
Expand Down Expand Up @@ -385,8 +385,8 @@ trait LensFunctions extends LensFamilyFunctions {

def factorLens[A, B, C]: ((A, B) \/ (A, C)) @> (A, B \/ C) =
lens(e => Store({
case (a, -\/(b)) => -\/(a, b)
case (a, \/-(c)) => \/-(a, c)
case (a, -\/(b)) => -\/((a, b))
case (a, \/-(c)) => \/-((a, c))
}, e match {
case -\/((a, b)) => (a, -\/(b))
case \/-((a, c)) => (a, \/-(c))
Expand All @@ -398,8 +398,8 @@ trait LensFunctions extends LensFamilyFunctions {
case -\/((aa, bb)) => (aa, -\/(bb))
case \/-((aa, cc)) => (aa, \/-(cc))
}, e match {
case -\/(b) => -\/(a, b)
case \/-(c) => \/-(a, c)
case -\/(b) => -\/((a, b))
case \/-(c) => \/-((a, c))

})
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/scalaz/ListT.scala
Expand Up @@ -8,7 +8,7 @@ final case class ListT[M[_], A](run: M[IList[A]]){
def uncons(implicit M: Applicative[M]): M[Option[(A, ListT[M, A])]] = {
M.map(run) {
case INil() => None
case ICons(listHead, listTail) => Some(listHead, new ListT(M.point(listTail)))
case ICons(listHead, listTail) => Some((listHead, new ListT(M.point(listTail))))
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/scalaz/Maybe.scala
Expand Up @@ -172,7 +172,7 @@ object Maybe extends MaybeInstances {
final def fromOption[A](oa: Option[A]): Maybe[A] =
std.option.cata(oa)(just, empty)

def fromTryCatchThrowable[T, E <: Throwable](a: => T)(implicit nn: NotNothing[E], ex: ClassTag[E]): Maybe[T] = try {
def fromTryCatchThrowable[T, E <: Throwable: NotNothing](a: => T)(implicit ex: ClassTag[E]): Maybe[T] = try {
just(a)
} catch {
case e if ex.runtimeClass.isInstance(e) => empty
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/scalaz/MonadError.scala
Expand Up @@ -17,7 +17,7 @@ trait MonadError[F[_], S] extends Monad[F] { self =>
def errorsRaised[A](a: A, e: S)(implicit FEA: Equal[F[A]]): Boolean =
FEA.equal(bind(point(a))(_ => raiseError(e)), raiseError(e))
def errorsStopComputation[A](e: S, a: A)(implicit FEA: Equal[F[A]]): Boolean =
FEA.equal(bind(raiseError(e))(_ => point(a)), raiseError(e))
FEA.equal(bind(raiseError(e))(point), raiseError(e))
}
def monadErrorLaw = new MonadErrorLaw {}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/scalaz/OptionT.scala
Expand Up @@ -279,7 +279,7 @@ private trait OptionTMonadListen[F[_], W] extends MonadListen[OptionT[F, ?], W]
def listen[A](ma: OptionT[F, A]): OptionT[F, (A, W)] = {
val tmp = MT.bind[(Option[A], W), Option[(A, W)]](MT.listen(ma.run)) {
case (None, _) => MT.point(None)
case (Some(a), w) => MT.point(Some(a, w))
case (Some(a), w) => MT.point(Some((a, w)))
}

OptionT.optionT[F].apply[(A, W)](tmp)
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/scalaz/PLens.scala
Expand Up @@ -421,11 +421,11 @@ trait PLensFunctions extends PLensInstances with PLensFamilyFunctions {
t match {
case (_, (k, _), _) if p(k) => Some(t)
case (_, _ , Nil) => None
case (l, x , r::rs) => lookupr((x::l, r, rs))
case (l, x , r::rs) => lookupr((x :: l, r, rs))
}
plens {
case Nil => None
case h :: t => lookupr(Nil, h, t) map {
case h :: t => lookupr((Nil, h, t)) map {
case (l, (k, v), r) => Store(w => l reverse_::: (k, w) :: r, v)
}
}
Expand Down Expand Up @@ -464,7 +464,7 @@ trait PLensFunctions extends PLensInstances with PLensFamilyFunctions {
}
plens {
case INil() => None
case ICons(h, t) => lookupr(INil(), h, t) map {
case ICons(h, t) => lookupr((IList.empty, h, t)) map {
case (l, (k, v), r) => Store(w => l reverse_::: (k, w) :: r, v)
}
}
Expand Down Expand Up @@ -512,11 +512,11 @@ trait PLensFunctions extends PLensInstances with PLensFamilyFunctions {
t match {
case (_, (k, _), _) if p(k) => Some(t)
case (_, _ , Stream.Empty) => None
case (l, x , r #:: rs) => lookupr(x #:: l, r, rs)
case (l, x , r #:: rs) => lookupr((x #:: l, r, rs))
}
plens {
case Stream.Empty => None
case h #:: t => lookupr(Stream.empty, h, t) map {
case h #:: t => lookupr((Stream.empty, h, t)) map {
case (l, (k, v), r) => Store(w => l.reverse #::: (k, w) #:: r, v)
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/scalaz/Representable.scala
Expand Up @@ -47,7 +47,7 @@ sealed abstract class RepresentableInstances {
object Representable extends RepresentableInstances

/** Corepresentable functors */
abstract class Corepresentable[F[_], X](implicit F: Contravariant[F]) {
abstract class Corepresentable[F[_]: Contravariant, X]() {
def corep[A](f: A => X): F[A]
def uncorep[A](f: F[A]): A => X

Expand Down

0 comments on commit f127e47

Please sign in to comment.