You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importscala.collection.immutable.QueueobjectMain {
defmain(args: Array[String]) = {
valx:Queue[Int] =Queue()
x match {
case _ :+ _ => println("something")
caseQueue() => println("empty")
}
}
}
Problem
At compilation with sbt, the following warning appears:
match may not be exhaustive.
[warn] It would fail on the following inputs: EmptyQueue, Queue()
[warn] x match {
[warn] ^
I would expect no warning as the matching should be complete having tested both the non-empty and empty Queue. I tested the execution with both val x: Queue[Int] = Queue() and val: Queue[Int] = Queue.empty[Int] and both work fine.
Activity
azarzadavila commentedon Nov 30, 2022
This is probably linked with #12252
som-snytt commentedon Nov 30, 2022
collection.:+
hasunapply
that returnsOption[(C, A)]
for(init, last)
.It is refutable. The question is whether to use "special knowledge" about this extractor when emitting warnings because it is so visible.
I wonder if there is a FAQ about
Seq
-extraction.som-snytt commentedon Nov 30, 2022
Maybe they need irrefutable
:+_!
...