Incorrect inexhaustivity warning when leafs are defined in an unrelated sealed trait
See original GitHub issueCompiler version
3.1.1
Minimized code
Here is a Scastie.
The exhaustivity check fails when instances of Schema are defined in a trait.
sealed trait Schema[A]
object Schema extends RecordInstances
sealed trait RecordInstances:
case class Field[A]() extends Schema[A]
case object Thing extends Schema[Int]
import Schema._
// Match not exhaustive error! (with fatal warnings :P)
def handle[A](schema: Schema[A]) =
schema match
case Field() => println("field")
case Thing => println("thing")
Expectation
While it is a bit odd to define these instances in a trait, I would still expect this to correctly check exhaustivity. Scala 2 works as expected here.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Match may not be exhaustive warning is incorrect
The Scala compiler won't give exhaustive match warnings for non-sealed traits (like your Foo ). This explains why fooThis and fooThat ...
Read more >Incorrect match inexhaustive warnings in Scala 2.13.4
Basically the compiler is saying that the unhandled cases are those where Success.unapply and Error.unapply return None , which we know to be ......
Read more >Does the +: extractor break exhaustive match checking?
No, it isn't. It is a case class and one that is a member of an ADT (a sealed trait ). The compiler...
Read more >Enforcement Guidance on the Consideration of Arrest and ...
Title VII liability for employment discrimination is determined using two analytic frameworks: "disparate treatment" and "disparate impact.
Read more >Review of Four FISA Applications and Other Aspects of the ...
opening the Crossfire Hurricane investigation stated ... Department and FBI policy leaves to the discretion of. FBI officials.
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
That looks like an unrelated bug (missing substitution of RecordInstances.this into Schema), could you open a separate issue for it?
Oh yeah… Don’t know why that didn’t trigger fatal warnings for me in Scala 2. The solution for me was to replace these traits with
// RECORD INSTANCES
comment headers instead 😛. I think someone just wanted the organizational niceties of traits to organize a very large sealed trait file.