Skip to content

Commit 16703e8

Browse files
[KAIZEN] Turn some warnings into errors (#1081)
* [KAIZEN] Turn some warnings into errors Print summaries for the remaining ones * [KAIZEN] Fix formatting * [KAIZEN] Full warnings flag * [KAIZEN] No errors in nix build * [KAIZEN] Refactor build.sbt Retain old settings for Compile/doc (otherwise derivation build fails in buildkite) * [KAIZEN] Split -W:conf into multiple lines .
1 parent 8c9ec4c commit 16703e8

File tree

12 files changed

+143
-55
lines changed

12 files changed

+143
-55
lines changed

build.sbt

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,35 @@ val `scala-2.12` = "2.12.13"
4444
val `scala-2.13` = "2.13.6"
4545
val supportedScalaVersions = List(`scala-2.12`, `scala-2.13`)
4646

47+
val baseScalacOptions = Seq(
48+
"-unchecked",
49+
"-deprecation",
50+
"-feature",
51+
"-Ywarn-unused",
52+
"-Xlint",
53+
"-encoding",
54+
"utf-8"
55+
)
56+
57+
// https://www.scala-lang.org/2021/01/12/configuring-and-suppressing-warnings.html
58+
// cat={warning-name}:ws prints a summary with the number of warnings of the given type
59+
// any:e turns all remaining warnings into errors
60+
val fatalWarnings = Seq(
61+
if (sys.env.get("MANTIS_FULL_WARNS").contains("true")) {
62+
"-Wconf:any:w"
63+
}
64+
else {
65+
"-Wconf:" ++ Seq(
66+
// Let's turn those gradually into errors:
67+
"cat=deprecation:ws",
68+
"cat=lint-package-object-classes:ws",
69+
"cat=unused:ws",
70+
"cat=lint-infer-any:ws",
71+
"cat=lint-byname-implicit:ws",
72+
"cat=other-match-analysis:ws",
73+
"any:e").mkString(",")
74+
}) ++ Seq("-Ypatmat-exhaust-depth", "off")
75+
4776
def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
4877
name := projectName,
4978
organization := "io.iohk",
@@ -59,23 +88,15 @@ def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
5988
resolvers += "Sonatype OSS Snapshots".at("https://oss.sonatype.org/content/repositories/snapshots"),
6089
(Test / testOptions) += Tests
6190
.Argument(TestFrameworks.ScalaTest, "-l", "EthashMinerSpec"), // miner tests disabled by default,
62-
scalacOptions := Seq(
63-
"-unchecked",
64-
"-deprecation",
65-
"-feature",
66-
// "-Xfatal-warnings", // disabled until unused are removed
67-
"-Ywarn-unused",
68-
"-Xlint",
69-
"-encoding",
70-
"utf-8"
71-
),
91+
scalacOptions := baseScalacOptions ++ fatalWarnings,
7292
scalacOptions ++= (if (mantisDev) Seq.empty else compilerOptimizationsForProd),
7393
(Compile / console / scalacOptions) ~= (_.filterNot(
7494
Set(
7595
"-Ywarn-unused-import",
7696
"-Xfatal-warnings"
7797
)
7898
)),
99+
(Compile / doc / scalacOptions) := baseScalacOptions,
79100
scalacOptions ~= (options => if (mantisDev) options.filterNot(_ == "-Xfatal-warnings") else options),
80101
Test / parallelExecution := true,
81102
(Test / testOptions) += Tests.Argument("-oDG"),

src/it/scala/io/iohk/ethereum/txExecTest/util/DumpChainApp.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ object DumpChainApp
119119
override val forkResolverOpt: Option[ForkResolver] = DumpChainApp.forkResolverOpt
120120
override val nodeStatusHolder: AtomicReference[NodeStatus] = DumpChainApp.nodeStatusHolder
121121
override val peerConfiguration: PeerConfiguration = peerConfig
122+
// FIXME: Selecting value blockchain from object DumpChainApp, which extends scala.DelayedInit, is likely to yield an uninitialized value
123+
@annotation.nowarn
122124
override val blockchain: Blockchain = DumpChainApp.blockchain
125+
// FIXME: Selecting value blockchainReader from object DumpChainApp, which extends scala.DelayedInit, is likely to yield an uninitialized value
126+
@annotation.nowarn
123127
override val blockchainReader: BlockchainReader = DumpChainApp.blockchainReader
124128
override val appStateStorage: AppStateStorage = storagesInstance.storages.appStateStorage
125129
override val blockchainConfig: BlockchainConfig = Config.blockchains.blockchainConfig

src/main/scala/io/iohk/ethereum/blockchain/sync/fast/SyncStateScheduler.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,16 @@ object SyncStateScheduler {
407407
// needs to be provided
408408
go(
409409
currentRequests - parent,
410-
currentBatch + (parent -> (parentRequest.resolvedData.getOrElse(
411-
throw new IllegalStateException(
412-
s"Critical error. Parent ${parentRequest.nodeHash} without resolved data"
410+
currentBatch + (parent -> (
411+
(
412+
parentRequest.resolvedData.getOrElse(
413+
throw new IllegalStateException(
414+
s"Critical error. Parent ${parentRequest.nodeHash} without resolved data"
415+
)
416+
),
417+
parentRequest.requestType
413418
)
414-
), parentRequest.requestType)),
419+
)),
415420
parentsToCheck.tail ++ parentRequest.parents
416421
)
417422
} else {
@@ -424,7 +429,7 @@ object SyncStateScheduler {
424429
}
425430

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

429434
val (newRequests, newBatch) = go(newActive, newMemBatch, request.parents)
430435
copy(activeRequest = newRequests, memBatch = newBatch)

src/main/scala/io/iohk/ethereum/db/storage/ReferenceCountNodeStorage.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class ReferenceCountNodeStorage(nodeStorage: NodesStorage, bn: BigInt) extends N
8282
StoredNode.withoutReferences(nodeEncoded) -> StoredNodeSnapshot(nodeKey, None)
8383
) // if it's new, return an empty stored node
8484

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

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

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

src/main/scala/io/iohk/ethereum/domain/BlockchainWriter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class BlockchainWriter(
9393
BestBlockLatestCheckpointNumbers(number, latestCheckpointNumber)
9494
)
9595

96-
private def persistBestBlocksData(): Unit = {
96+
private def persistBestBlocksData: () => Unit = () => {
9797
val currentBestBlockNumber = blockchainMetadata.bestKnownBlockAndLatestCheckpoint.get().bestBlockNumber
9898
val currentBestCheckpointNumber = blockchainMetadata.bestKnownBlockAndLatestCheckpoint.get().latestCheckpointNumber
9999
log.debug(

src/main/scala/io/iohk/ethereum/faucet/jsonrpc/FaucetBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ trait FaucetJsonRpcHttpServerBuilder {
100100
trait ShutdownHookBuilder {
101101
self: ActorSystemBuilder with FaucetConfigBuilder with Logger =>
102102

103-
def shutdown(): Unit =
103+
def shutdown: () => Unit = () =>
104104
Await.ready(
105105
system
106106
.terminate()

src/main/scala/io/iohk/ethereum/jsonrpc/serialization/JsonEncoder.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.json4s.JValue
1010

1111
import io.iohk.ethereum.jsonrpc.JsonMethodsImplicits
1212

13+
@FunctionalInterface
1314
trait JsonEncoder[T] {
1415
def encodeJson(t: T): JValue
1516
}

src/main/scala/io/iohk/ethereum/ledger/StxLedger.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ object StxLedger {
8484
* @return minimal value for which provided function do not return error
8585
*/
8686
@tailrec
87-
private[ledger] def binaryChop[Error](min: BigInt, max: BigInt)(f: BigInt => Option[Error]): BigInt = {
87+
private[ledger] def binaryChop[Err](min: BigInt, max: BigInt)(f: BigInt => Option[Err]): BigInt = {
8888
assert(min <= max)
8989

9090
if (min == max)

src/main/scala/io/iohk/ethereum/nodebuilder/NodeBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ trait PortForwardingBuilder {
804804

805805
trait ShutdownHookBuilder {
806806
self: Logger =>
807-
def shutdown(): Unit = {
807+
def shutdown: () => Unit = () => {
808808
/* No default behaviour during shutdown. */
809809
}
810810

src/main/scala/io/iohk/ethereum/nodebuilder/StdNode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ abstract class BaseNode extends Node {
106106
"PeriodicDBConsistencyCheck"
107107
)
108108

109-
override def shutdown(): Unit = {
109+
override def shutdown: () => Unit = () => {
110110
def tryAndLogFailure(f: () => Any): Unit = Try(f()) match {
111111
case Failure(e) => log.warn("Error while shutting down...", e)
112112
case Success(_) =>

src/test/scala/io/iohk/ethereum/blockchain/sync/SyncControllerSpec.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,6 @@ class SyncControllerSpec
621621
this
622622

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

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

645643
case SendMessage(msg: GetNodeDataEnc, peer) if !onlyPivot =>
646644
stateDownloadStarted = true
647-
msg.underlyingMsg
648645
if (!failedNodeRequest) {
649646
sender ! MessageFromPeer(NodeData(Seq(defaultStateMptLeafWithAccount)), peer)
650647
}

0 commit comments

Comments
 (0)