Skip to content

[KAIZEN] Turn some warnings into errors #1079

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

Closed
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
41 changes: 31 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,35 @@ val `scala-2.12` = "2.12.13"
val `scala-2.13` = "2.13.6"
val supportedScalaVersions = List(`scala-2.12`, `scala-2.13`)

val baseScalacOptions = Seq(
"-unchecked",
"-deprecation",
"-feature",
"-Ywarn-unused",
"-Xlint",
"-encoding",
"utf-8"
)

// https://www.scala-lang.org/2021/01/12/configuring-and-suppressing-warnings.html
// cat={warning-name}:ws prints a summary with the number of warnings of the given type
// any:e turns all remaining warnings into errors
val fatalWarnings = Seq(
if (sys.env.get("MANTIS_FULL_WARNS").contains("true")) {
"-Wconf:any:w"
}
else {
"-Wconf:" ++ Seq(
// Let's turn those gradually into errors:
"cat=deprecation:ws",
"cat=lint-package-object-classes:ws",
"cat=unused:ws",
"cat=lint-infer-any:ws",
"cat=lint-byname-implicit:ws",
"cat=other-match-analysis:ws",
"any:e").mkString(",")
}) ++ Seq("-Ypatmat-exhaust-depth", "off")

def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
name := projectName,
organization := "io.iohk",
Expand All @@ -59,23 +88,15 @@ def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
resolvers += "Sonatype OSS Snapshots".at("https://oss.sonatype.org/content/repositories/snapshots"),
(Test / testOptions) += Tests
.Argument(TestFrameworks.ScalaTest, "-l", "EthashMinerSpec"), // miner tests disabled by default,
scalacOptions := Seq(
"-unchecked",
"-deprecation",
"-feature",
// "-Xfatal-warnings", // disabled until unused are removed
"-Ywarn-unused",
"-Xlint",
"-encoding",
"utf-8"
),
scalacOptions := baseScalacOptions ++ fatalWarnings,
scalacOptions ++= (if (mantisDev) Seq.empty else compilerOptimizationsForProd),
(Compile / console / scalacOptions) ~= (_.filterNot(
Set(
"-Ywarn-unused-import",
"-Xfatal-warnings"
)
)),
(Compile / doc / scalacOptions) := baseScalacOptions,
scalacOptions ~= (options => if (mantisDev) options.filterNot(_ == "-Xfatal-warnings") else options),
Test / parallelExecution := true,
(Test / testOptions) += Tests.Argument("-oDG"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ object DumpChainApp
override val forkResolverOpt: Option[ForkResolver] = DumpChainApp.forkResolverOpt
override val nodeStatusHolder: AtomicReference[NodeStatus] = DumpChainApp.nodeStatusHolder
override val peerConfiguration: PeerConfiguration = peerConfig
// FIXME: Selecting value blockchain from object DumpChainApp, which extends scala.DelayedInit, is likely to yield an uninitialized value
@annotation.nowarn
override val blockchain: Blockchain = DumpChainApp.blockchain
// FIXME: Selecting value blockchainReader from object DumpChainApp, which extends scala.DelayedInit, is likely to yield an uninitialized value
@annotation.nowarn
override val blockchainReader: BlockchainReader = DumpChainApp.blockchainReader
override val appStateStorage: AppStateStorage = storagesInstance.storages.appStateStorage
override val blockchainConfig: BlockchainConfig = Config.blockchains.blockchainConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,16 @@ object SyncStateScheduler {
// needs to be provided
go(
currentRequests - parent,
currentBatch + (parent -> (parentRequest.resolvedData.getOrElse(
throw new IllegalStateException(
s"Critical error. Parent ${parentRequest.nodeHash} without resolved data"
currentBatch + (parent -> (
(
parentRequest.resolvedData.getOrElse(
throw new IllegalStateException(
s"Critical error. Parent ${parentRequest.nodeHash} without resolved data"
)
),
parentRequest.requestType
)
), parentRequest.requestType)),
)),
parentsToCheck.tail ++ parentRequest.parents
)
} else {
Expand All @@ -424,7 +429,7 @@ object SyncStateScheduler {
}

val newActive = activeRequest - request.nodeHash
val newMemBatch = memBatch + (request.nodeHash -> (request.resolvedData.get, request.requestType))
val newMemBatch = memBatch + (request.nodeHash -> ((request.resolvedData.get, request.requestType)))

val (newRequests, newBatch) = go(newActive, newMemBatch, request.parents)
copy(activeRequest = newRequests, memBatch = newBatch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ReferenceCountNodeStorage(nodeStorage: NodesStorage, bn: BigInt) extends N
StoredNode.withoutReferences(nodeEncoded) -> StoredNodeSnapshot(nodeKey, None)
) // if it's new, return an empty stored node

storedNodes + (nodeKey -> (storedNode.incrementReferences(1, blockNumber), snapshot))
storedNodes + (nodeKey -> ((storedNode.incrementReferences(1, blockNumber), snapshot)))
}

private def prepareRemovalChanges(
Expand All @@ -94,7 +94,7 @@ class ReferenceCountNodeStorage(nodeStorage: NodesStorage, bn: BigInt) extends N
val maybeStoredNode: Option[(StoredNode, StoredNodeSnapshot)] = getFromChangesOrStorage(nodeKey, storedNodes)

maybeStoredNode.fold(storedNodes) { case (storedNode, snapshot) =>
storedNodes + (nodeKey -> (storedNode.decrementReferences(1, blockNumber), snapshot))
storedNodes + (nodeKey -> ((storedNode.decrementReferences(1, blockNumber), snapshot)))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class BlockchainWriter(
BestBlockLatestCheckpointNumbers(number, latestCheckpointNumber)
)

private def persistBestBlocksData(): Unit = {
private def persistBestBlocksData: () => Unit = () => {
val currentBestBlockNumber = blockchainMetadata.bestKnownBlockAndLatestCheckpoint.get().bestBlockNumber
val currentBestCheckpointNumber = blockchainMetadata.bestKnownBlockAndLatestCheckpoint.get().latestCheckpointNumber
log.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ trait FaucetJsonRpcHttpServerBuilder {
trait ShutdownHookBuilder {
self: ActorSystemBuilder with FaucetConfigBuilder with Logger =>

def shutdown(): Unit =
def shutdown: () => Unit = () =>
Await.ready(
system
.terminate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.json4s.JValue

import io.iohk.ethereum.jsonrpc.JsonMethodsImplicits

@FunctionalInterface
trait JsonEncoder[T] {
def encodeJson(t: T): JValue
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/io/iohk/ethereum/ledger/StxLedger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ object StxLedger {
* @return minimal value for which provided function do not return error
*/
@tailrec
private[ledger] def binaryChop[Error](min: BigInt, max: BigInt)(f: BigInt => Option[Error]): BigInt = {
private[ledger] def binaryChop[Err](min: BigInt, max: BigInt)(f: BigInt => Option[Err]): BigInt = {
assert(min <= max)

if (min == max)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ trait PortForwardingBuilder {

trait ShutdownHookBuilder {
self: Logger =>
def shutdown(): Unit = {
def shutdown: () => Unit = () => {
/* No default behaviour during shutdown. */
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/io/iohk/ethereum/nodebuilder/StdNode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ abstract class BaseNode extends Node {
"PeriodicDBConsistencyCheck"
)

override def shutdown(): Unit = {
override def shutdown: () => Unit = () => {
def tryAndLogFailure(f: () => Any): Unit = Try(f()) match {
case Failure(e) => log.warn("Error while shutting down...", e)
case Success(_) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,6 @@ class SyncControllerSpec
this

case SendMessage(msg: GetReceiptsEnc, peer) if !onlyPivot =>
msg.underlyingMsg
if (failedReceiptsTries > 0) {
sender ! MessageFromPeer(Receipts(Seq()), peer)
this.copy(failedReceiptsTries = failedReceiptsTries - 1)
Expand All @@ -632,7 +631,6 @@ class SyncControllerSpec
}

case SendMessage(msg: GetBlockBodiesEnc, peer) if !onlyPivot =>
msg.underlyingMsg
if (failedBodiesTries > 0) {
sender ! MessageFromPeer(BlockBodies(Seq()), peer)
this.copy(failedBodiesTries = failedBodiesTries - 1)
Expand All @@ -644,7 +642,6 @@ class SyncControllerSpec

case SendMessage(msg: GetNodeDataEnc, peer) if !onlyPivot =>
stateDownloadStarted = true
msg.underlyingMsg
if (!failedNodeRequest) {
sender ! MessageFromPeer(NodeData(Seq(defaultStateMptLeafWithAccount)), peer)
}
Expand Down
Loading