Spurious non-exhaustivity warning
See original GitHub issueCompiler version
3.2.0 with -Ycheck-all-patmat
Minimized code
sealed trait Nat
case class Zero() extends Nat
case class Succ[N <: Nat](n: N) extends Nat
type PredOrZeroOption[N <: Nat] <: Option[Nat] = N match
case Zero => None.type
case Succ[predN] => Some[predN]
trait A[N <: Nat]:
def foo: PredOrZeroOption[N]
object A:
def unapply[N <: Nat](a: A[N]): PredOrZeroOption[N] = a.foo
class B[PredN <: Nat](n: PredN) extends A[Succ[PredN]]:
override def foo: Some[PredN] = Some(n)
@main def main(): Unit =
val a = B(Zero())
a.foo match
case Some(pred) => println(pred)
a match
case A(pred) => println(pred)
Output
match may not be exhaustive.
It would fail on pattern case: _: B[Zero]
Expectation
No warning.
Note there is no warning for the a.foo
match, which is equivalent.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Spurious 'non-exhaustive patterns' error · Issue #15080 · rust-lang ...
It looks like #14731 introduced a regression. The following used to work: fn main() { let mut x = &[1, 2, 3, 4];...
Read more >Spurious non-exhaustive pattern match warnings are given ...
Spurious non-exhaustive pattern match warnings are given using GADTs ; Resolution, Unresolved ; Component, Compiler ; Test case ; Differential ...
Read more >rust match in match: "spurious" non exhaustive error on simple ...
I understand this error, and I know how to "brutally" fix it (similarly to Non-exhaustive patterns - Rust match expressions by adding a:...
Read more >Trouble with 2.13.4 exhaustivity checking being too strict
Hi there,. I'm trying to migrate some of our company's projects to Scala 2.13.4 and I'm hitting some problems with the new exhaustivity ......
Read more >GADTs meet their match (Extended Version) - KU Leuven
day's compilers generate bogus warnings when the programmer ... it is non-empty, the clauses are not exhaustive, and a warning should be generated....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dwijnand Thank you! Makes sense.
One thing that might improve upon the current state of affairs would be to have two different types of warnings:
The latter warnings could be shown only when somehow enabled.
P.S.: The latter warning could also be split further into two sub-cases:
Yeah, that’s what private means…
Mostly there aren’t. Things like explicit nulls and safe-init will become on by default. But debug pos I don’t even understand why you use it, but I also don’t know what it does. But it sounds like an always private flag. In general they need a ticket, a reason and an effort to become stable, non-private feature or on by default.
There’s no (public) feature for that. But I would also want it, so I would back a proposal to add that. I’m fairly certain we had a flag like that in Scala 2.
Sure, sort of. For some code we don’t check for exhaustivity, it doesn’t seem to calculate the right thing. It’s not worth keeping a ticket open for that - IMO.