question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect inexhaustivity warning when leafs are defined in an unrelated sealed trait

See original GitHub issue

Compiler 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:open
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
smartercommented, Apr 26, 2022

It causes another similar compiler error here (scastie.scala-lang.org/2ME3I1HIQuyUAe67T2jziw)

That looks like an unrelated bug (missing substitution of RecordInstances.this into Schema), could you open a separate issue for it?

0reactions
kitlangtoncommented, Apr 26, 2022

Also Scala 2 warns. It would fail on the following inputs: Field(), Thing, _

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found