Skip to content

Commit 5f5c838

Browse files
committed
fix: enable strict-unsealed-patmat lint and fix exhaustiveness warnings
Motivation: The strict-unsealed-patmat lint was disabled globally in #264 to unblock the build, leaving many pattern matches on non-sealed traits unchecked. Issue #265 tracks re-enabling this lint. Modification: Remove the -Xlint:-strict-unsealed-patmat silencing flag from PekkoDisciplinePlugin for Scala 2.13. Fix all resulting exhaustiveness warnings across the codebase: - Seal Command traits where all subtypes are in the same file - Add @nowarn annotations where traits are intentionally non-sealed (cross-file protocols in tutorials) - Add catch-all cases for matches on OptionVal and other extractor-only types (Collections, stream operators) Result: The strict-unsealed-patmat lint is now active for Scala 2.13, catching future pattern match exhaustiveness issues at compile time. Tests: sbt "docs / Test / compile" — success, no exhaustiveness errors References: Fixes #265
1 parent d50f1ac commit 5f5c838

20 files changed

Lines changed: 32 additions & 14 deletions

File tree

actor-typed-tests/src/test/scala/org/apache/pekko/actor/typed/delivery/TestProducerWithAsk.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import pekko.util.Timeout
2626

2727
object TestProducerWithAsk {
2828

29-
trait Command
29+
sealed trait Command
3030
final case class RequestNext(askTo: ActorRef[ProducerController.MessageWithConfirmation[TestConsumer.Job]])
3131
extends Command
3232
private case object Tick extends Command

actor-typed-tests/src/test/scala/org/apache/pekko/actor/typed/delivery/TestProducerWorkPulling.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import pekko.actor.typed.scaladsl.Behaviors
2222

2323
object TestProducerWorkPulling {
2424

25-
trait Command
25+
sealed trait Command
2626
final case class RequestNext(sendTo: ActorRef[TestConsumer.Job]) extends Command
2727
private case object Tick extends Command
2828

actor-typed-tests/src/test/scala/org/apache/pekko/actor/typed/eventstream/EventStreamDocSpec.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ object EventStreamDocSpec {
8282
case UnhandledMessage(message, sender, recipient) =>
8383
context.log.info("UnhandledMessage received from sender ({}) to recipient ({}) with message: {}",
8484
sender.path.name, recipient.path.name, message.toString)
85+
86+
case other =>
87+
context.log.warn("Unexpected AllDeadLetters: {}", other)
8588
}
8689
Behaviors.same
8790
}

actor/src/main/scala/org/apache/pekko/util/Collections.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ private[pekko] object Collections {
3939
pf.applyOrElse(t, NotApplied) match {
4040
case _: NotApplied.type => // do nothing
4141
case r: R @unchecked => builder += r
42+
case _ => // unreachable, NotApplied handled above, everything else is R
4243
}
4344
})
4445
builder.result()

bench-jmh/src/main/scala/org/apache/pekko/actor/typed/delivery/ReliableDeliveryBenchmark.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import pekko.actor.typed.scaladsl.Behaviors
3636
import com.typesafe.config.ConfigFactory
3737

3838
object Producer {
39-
trait Command
39+
sealed trait Command
4040

4141
case object Run extends Command
4242
private case class WrappedRequestNext(r: ProducerController.RequestNext[Consumer.Command]) extends Command
@@ -83,7 +83,7 @@ object Producer {
8383
}
8484

8585
object Consumer {
86-
trait Command
86+
sealed trait Command
8787

8888
case object TheMessage extends Command
8989

@@ -111,7 +111,7 @@ object Consumer {
111111
}
112112

113113
object WorkPullingProducer {
114-
trait Command
114+
sealed trait Command
115115

116116
case object Run extends Command
117117
private case class WrappedRequestNext(r: WorkPullingProducerController.RequestNext[Consumer.Command]) extends Command
@@ -148,7 +148,7 @@ object WorkPullingProducer {
148148

149149
object Guardian {
150150

151-
trait Command
151+
sealed trait Command
152152
final case class RunPointToPoint(id: String, numberOfMessages: Int, useAsk: Boolean, replyTo: ActorRef[Done])
153153
extends Command
154154
final case class RunWorkPulling(id: String, numberOfMessages: Int, workers: Int, replyTo: ActorRef[Done])

cluster-sharding-typed/src/multi-jvm/scala/org/apache/pekko/cluster/sharding/typed/ShardedDaemonProcessSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ object ShardedDaemonProcessSpec extends MultiNodeConfig {
4343
case class ProcessActorEvent(id: Int, event: Any) extends CborSerializable
4444

4545
object ProcessActor {
46-
trait Command
46+
sealed trait Command
4747
case object Stop extends Command
4848

4949
def apply(id: Int): Behavior[Command] = Behaviors.setup { ctx =>

cluster-sharding-typed/src/test/scala/docs/org/apache/pekko/cluster/sharding/typed/ShardingCompileOnlySpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ object ShardingCompileOnlySpec {
161161

162162
// a sharded counter that sends responses to another sharded actor
163163
object Counter {
164-
trait Command
164+
sealed trait Command
165165
case object Increment extends Command
166166
final case class GetValue(replyToEntityId: String) extends Command
167167
val TypeKey: EntityTypeKey[Command] = EntityTypeKey[Command]("example-sharded-counter")

cluster-sharding/src/test/scala/org/apache/pekko/cluster/sharding/ShardRegionDataTypesSpec.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class ShardRegionDataTypesSpec extends AnyWordSpec with Matchers {
5858
s match {
5959
case ShardRegionStats(stats) =>
6060
stats shouldBe Map("s1" -> 1)
61+
case _ => fail("Should match ShardRegionStats")
6162
}
6263
}
6364

@@ -103,6 +104,7 @@ class ShardRegionDataTypesSpec extends AnyWordSpec with Matchers {
103104
state match {
104105
case CurrentShardRegionState(shards) =>
105106
shards shouldBe Set(ShardState("s1", Set("e1")))
107+
case _ => fail("Should match CurrentShardRegionState")
106108
}
107109
}
108110

docs/src/test/scala/docs/actor/typed/CoordinatedActorShutdownSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CoordinatedActorShutdownSpec {
2828
// #coordinated-shutdown-addTask
2929
object MyActor {
3030

31-
trait Messages
31+
sealed trait Messages
3232
case class Stop(replyTo: ActorRef[Done]) extends Messages
3333

3434
def behavior: Behavior[Messages] =

docs/src/test/scala/docs/actor/typed/SharedMutableStateDocSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class SharedMutableStateDocSpec {
2727
def expensiveCalculation(): Future[String] = ???
2828

2929
object MyActor {
30-
trait Command
30+
sealed trait Command
3131
case class Message(msg: String, replyTo: ActorRef[Any]) extends Command
3232
case class UpdateState(newState: String) extends Command
3333

0 commit comments

Comments
 (0)