Skip to content

Commit

Permalink
Enable scalac compilation flags
Browse files Browse the repository at this point in the history
  • Loading branch information
blemale committed Apr 28, 2019
1 parent 521f18d commit d8de35b
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 34 deletions.
76 changes: 75 additions & 1 deletion build.sbt
Expand Up @@ -23,4 +23,78 @@ libraryDependencies ++=
Scalatest % "test"
)

scalacOptions ++= Seq("-target:jvm-1.8")
scalacOptions ++= Seq("-target:jvm-1.8")

scalacOptions ++=
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) =>
Seq(
"-deprecation",
"-encoding", "UTF-8",
"-feature",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions",
"-unchecked",
"-Xfatal-warnings",
"-Xlint",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Xfuture",
"-Ywarn-unused-import"
)
case Some((2, 12)) =>
Seq(
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-encoding", "utf-8", // Specify character encoding used by source files.
"-explaintypes", // Explain type errors in more detail.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-language:existentials", // Existential types (besides wildcard types) can be written and inferred
"-language:experimental.macros", // Allow macro definition (besides implementation and application)
"-language:higherKinds", // Allow higher-kinded types
"-language:implicitConversions", // Allow definition of implicit functions called views
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access.
"-Xfatal-warnings", // Fail the compilation if there are any warnings.
"-Xfuture", // Turn on future language features.
"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
"-Xlint:by-name-right-associative", // By-name parameter of right associative operator.
"-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error.
"-Xlint:delayedinit-select", // Selecting member of DelayedInit.
"-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element.
"-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`.
"-Xlint:missing-interpolator", // A string literal appears to be missing an interpolator id.
"-Xlint:nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Xlint:nullary-unit", // Warn when nullary methods return Unit.
"-Xlint:option-implicit", // Option.apply used implicit view.
"-Xlint:package-object-classes", // Class or object defined in package object.
"-Xlint:poly-implicit-overload", // Parameterized overloaded implicit methods are not visible as view bounds.
"-Xlint:private-shadow", // A private field (or class parameter) shadows a superclass field.
"-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component.
"-Xlint:type-parameter-shadow", // A local type parameter shadows a type already in scope.
"-Xlint:unsound-match", // Pattern match may not be typesafe.
"-Yno-adapted-args", // Do not adapt an argument list (either by inserting () or creating a tuple) to match the receiver.
"-Ypartial-unification", // Enable partial unification in type constructor inference
"-Ywarn-dead-code", // Warn when dead code is identified.
"-Ywarn-extra-implicit", // Warn when more than one implicit parameter section is defined.
"-Ywarn-inaccessible", // Warn about inaccessible types in method signatures.
"-Ywarn-infer-any", // Warn when a type argument is inferred to be `Any`.
"-Ywarn-nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Ywarn-nullary-unit", // Warn when nullary methods return Unit.
"-Ywarn-numeric-widen", // Warn when numerics are widened.
"-Ywarn-unused:implicits", // Warn if an implicit parameter is unused.
"-Ywarn-unused:imports", // Warn if an import selector is not referenced.
"-Ywarn-unused:locals", // Warn if a local definition is unused.
"-Ywarn-unused:params", // Warn if a value parameter is unused.
"-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused.
"-Ywarn-unused:privates", // Warn if a private member is unused.
"-Ywarn-value-discard" // Warn when non-Unit expression results are unused.
)
case _ =>
Nil
})

scalacOptions in (Compile, console) --= Seq("-Ywarn-unused:imports", "-Xfatal-warnings")
8 changes: 4 additions & 4 deletions src/main/scala/com/github/blemale/scaffeine/Scaffeine.scala
Expand Up @@ -377,8 +377,8 @@ case class Scaffeine[K, V](underlying: caffeine.cache.Caffeine[K, V]) {

private[this] def toCacheLoader[K1 <: K, V1 <: V](
loader: K1 => V1,
allLoader: Option[Iterable[K1] => Map[K1, V1]] = None,
reloadLoader: Option[(K1, V1) => V1] = None
allLoader: Option[Iterable[K1] => Map[K1, V1]],
reloadLoader: Option[(K1, V1) => V1]
): caffeine.cache.CacheLoader[K1, V1] = allLoader match {
case Some(l) =>
new CacheLoaderAdapter[K1, V1](loader, reloadLoader) {
Expand All @@ -391,8 +391,8 @@ case class Scaffeine[K, V](underlying: caffeine.cache.Caffeine[K, V]) {

private[this] def toAsyncCacheLoader[K1 <: K, V1 <: V](
loader: K1 => Future[V1],
allLoader: Option[Iterable[K1] => Future[Map[K1, V1]]] = None,
reloadLoader: Option[(K1, V1) => Future[V1]] = None
allLoader: Option[Iterable[K1] => Future[Map[K1, V1]]],
reloadLoader: Option[(K1, V1) => Future[V1]]
): caffeine.cache.AsyncCacheLoader[K1, V1] = allLoader match {
case Some(l) =>
new AsyncCacheLoaderAdapter[K1, V1](loader, reloadLoader) {
Expand Down
Expand Up @@ -27,8 +27,8 @@ class AsyncCacheSpec
val cache = Scaffeine().buildAsync[String, String]()

cache.put("foo", Future.successful("present"))
val fooValue = cache.get("foo", k => "computed")
val barValue = cache.get("bar", k => "computed")
val fooValue = cache.get("foo", _ => "computed")
val barValue = cache.get("bar", _ => "computed")

fooValue.futureValue should be("present")
barValue.futureValue should be("computed")
Expand All @@ -38,8 +38,8 @@ class AsyncCacheSpec
val cache = Scaffeine().buildAsync[String, String]()

cache.put("foo", Future.successful("present"))
val fooValue = cache.getFuture("foo", k => Future.successful("computed"))
val barValue = cache.getFuture("bar", k => Future.successful("computed"))
val fooValue = cache.getFuture("foo", _ => Future.successful("computed"))
val barValue = cache.getFuture("bar", _ => Future.successful("computed"))

fooValue.futureValue should be("present")
barValue.futureValue should be("computed")
Expand Down
Expand Up @@ -15,7 +15,7 @@ class AsyncLoadingCacheSpec
"created with synchronous loader" should {

"get or load value" in {
val cache = Scaffeine().buildAsync[String, String]((key: String) => "loaded")
val cache = Scaffeine().buildAsync[String, String]((_: String) => "loaded")

cache.put("foo", Future.successful("present"))
val fooValue = cache.get("foo")
Expand All @@ -26,7 +26,7 @@ class AsyncLoadingCacheSpec
}

"get or load all given values" in {
val cache = Scaffeine().buildAsync[String, String]((key: String) => "loaded")
val cache = Scaffeine().buildAsync[String, String]((_: String) => "loaded")

cache.put("foo", Future.successful("present"))
val values = cache.getAll(List("foo", "bar"))
Expand All @@ -36,7 +36,7 @@ class AsyncLoadingCacheSpec

"get or bulk load all given values" in {
val cache = Scaffeine().buildAsync[String, String](
(key: String) => "loaded",
(_: String) => "loaded",
allLoader = Some((keys: Iterable[String]) => keys.map(_ -> "bulked").toMap)
)

Expand All @@ -47,7 +47,7 @@ class AsyncLoadingCacheSpec
}

"expose a synchronous view of itself" in {
val cache = Scaffeine().buildAsync[String, String]((key: String) => "loaded")
val cache = Scaffeine().buildAsync[String, String]((_: String) => "loaded")

val synchronousCache = cache.synchronous()

Expand All @@ -57,7 +57,7 @@ class AsyncLoadingCacheSpec

"created with asynchronous loader" should {
"get or load value" in {
val cache = Scaffeine().buildAsyncFuture[String, String]((key: String) => Future.successful("loaded"))
val cache = Scaffeine().buildAsyncFuture[String, String]((_: String) => Future.successful("loaded"))

cache.put("foo", Future.successful("present"))
val fooValue = cache.get("foo")
Expand All @@ -68,7 +68,7 @@ class AsyncLoadingCacheSpec
}

"get or load all given values" in {
val cache = Scaffeine().buildAsyncFuture[String, String]((key: String) => Future.successful("loaded"))
val cache = Scaffeine().buildAsyncFuture[String, String]((_: String) => Future.successful("loaded"))

cache.put("foo", Future.successful("present"))
val values = cache.getAll(List("foo", "bar"))
Expand All @@ -78,7 +78,7 @@ class AsyncLoadingCacheSpec

"get or bulk load all given values" in {
val cache = Scaffeine().buildAsyncFuture[String, String](
(key: String) => Future.successful("loaded"),
(_: String) => Future.successful("loaded"),
allLoader = Some((keys: Iterable[String]) => Future.successful(keys.map(_ -> "bulked").toMap))
)

Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/com/github/blemale/scaffeine/CacheSpec.scala
Expand Up @@ -23,8 +23,8 @@ class CacheSpec
val cache = Scaffeine().build[String, String]()
cache.put("foo", "present")

val present = cache.get("foo", key => "computed")
val computed = cache.get("bar", key => "computed")
val present = cache.get("foo", _ => "computed")
val computed = cache.get("bar", _ => "computed")

present should be("present")
computed should be("computed")
Expand Down
Expand Up @@ -9,13 +9,13 @@ class LoadingCacheSpec

"LoadingCache" should {
"be a cache" in {
val cache = Scaffeine().build[String, String]((key: String) => "computed")
val cache = Scaffeine().build[String, String]((_: String) => "computed")

cache shouldBe a[Cache[_, _]]
}

"get or load value" in {
val cache = Scaffeine().build[String, String]((key: String) => "computed")
val cache = Scaffeine().build[String, String]((_: String) => "computed")
cache.put("foo", "present")

val fooValue = cache.get("foo")
Expand All @@ -26,7 +26,7 @@ class LoadingCacheSpec
}

"get or load all given values" in {
val cache = Scaffeine().build[String, String]((key: String) => "computed")
val cache = Scaffeine().build[String, String]((_: String) => "computed")
cache.put("foo", "present")

val values = cache.getAll(List("foo", "bar"))
Expand All @@ -38,7 +38,7 @@ class LoadingCacheSpec
val cache =
Scaffeine()
.build[String, String](
loader = (key: String) => "computed",
loader = (_: String) => "computed",
allLoader = Some((keys: Iterable[String]) => keys.map(_ -> "bulked").toMap)
)
cache.put("foo", "present")
Expand All @@ -52,7 +52,7 @@ class LoadingCacheSpec
val cache =
Scaffeine()
.executor(DirectExecutor)
.build[String, String]((key: String) => "computed")
.build[String, String]((_: String) => "computed")

cache.put("foo", "present")
cache.refresh("foo")
Expand All @@ -66,8 +66,8 @@ class LoadingCacheSpec
Scaffeine()
.executor(DirectExecutor)
.build[String, String](
loader = (key: String) => "computed",
reloadLoader = Some((key: String, old: String) => "reload")
loader = (_: String) => "computed",
reloadLoader = Some((_: String, _: String) => "reload")
)

cache.put("foo", "present")
Expand Down
Expand Up @@ -12,8 +12,9 @@ class RemovalListenerSpec
class StubListener extends ((String, String, RemovalCause) => Unit) {
val callCounter = new AtomicInteger

override def apply(key: String, value: String, cause: RemovalCause): Unit =
callCounter.incrementAndGet()
override def apply(key: String, value: String, cause: RemovalCause): Unit = {
val _ = callCounter.incrementAndGet()
}
}

"Cache" should {
Expand Down
12 changes: 6 additions & 6 deletions src/test/scala/com/github/blemale/scaffeine/ScaffeineSpec.scala
Expand Up @@ -218,8 +218,8 @@ class ScaffeineSpec
Scaffeine()
.build[Int, Int](
loader = (key: Int) => key + 1,
allLoader = Some((keys: Iterable[Int]) => keys.map(i => (i -> (i + 1))).toMap),
reloadLoader = Some((key: Int, old: Int) => key + 1)
allLoader = Some((keys: Iterable[Int]) => keys.map(i => i -> (i + 1)).toMap),
reloadLoader = Some((key: Int, _: Int) => key + 1)
)

cache shouldBe a[LoadingCache[_, _]]
Expand All @@ -236,8 +236,8 @@ class ScaffeineSpec
Scaffeine()
.buildAsync[Int, Int](
loader = (key: Int) => key + 1,
allLoader = Some((keys: Iterable[Int]) => keys.map(i => (i -> (i + 1))).toMap),
reloadLoader = Some((key: Int, old: Int) => key + 1)
allLoader = Some((keys: Iterable[Int]) => keys.map(i => i -> (i + 1)).toMap),
reloadLoader = Some((key: Int, _: Int) => key + 1)
)

cache shouldBe a[AsyncLoadingCache[_, _]]
Expand All @@ -254,8 +254,8 @@ class ScaffeineSpec
Scaffeine()
.buildAsyncFuture[Int, Int](
loader = (key: Int) => Future.successful(key + 1),
allLoader = Some((keys: Iterable[Int]) => Future.successful(keys.map(i => (i -> (i + 1))).toMap)),
reloadLoader = Some((key: Int, old: Int) => Future.successful(key + 1))
allLoader = Some((keys: Iterable[Int]) => Future.successful(keys.map(i => i -> (i + 1)).toMap)),
reloadLoader = Some((key: Int, _: Int) => Future.successful(key + 1))
)

cache shouldBe a[AsyncLoadingCache[_, _]]
Expand Down
Expand Up @@ -11,7 +11,7 @@ class WeigherSpec
"use weigher for calculate size based eviction" in {
val cache = Scaffeine()
.executor(DirectExecutor)
.weigher[String, String]((key, value) => value.length)
.weigher[String, String]((_, value) => value.length)
.maximumWeight(10)
.build[String, String]()

Expand Down

0 comments on commit d8de35b

Please sign in to comment.