Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exhaustivity warning regression in 2.10.0-M7 vs -M6 and 2.9? #6450

Closed
scabug opened this issue Sep 29, 2012 · 2 comments
Closed

Exhaustivity warning regression in 2.10.0-M7 vs -M6 and 2.9? #6450

scabug opened this issue Sep 29, 2012 · 2 comments

Comments

@scabug
Copy link

scabug commented Sep 29, 2012

I got a new exhaustivity warning when switching to 2.10.0-M7 and it seems spurious to me, but it involves existentials so I'm not sure.

To reproduce this warning, we first need to define a sealed abstract class or sealed trait:

scala> sealed abstract class FoundNode[T]
defined class FoundNode

and then tuple it with another parameterized case class, like Some (a fresh case class would also be fine, but Option wouldn't).

scala> object Foo {
     | val v: (Some[_], FoundNode[_]) = (???, ???)
     |   v match {
     |     case (x: Some[t], _) =>
     |   }
     | }
<console>:10: warning: match may not be exhaustive.
It would fail on the following input: (_, _)
         v match {
         ^
defined module Foo

The warning is triggered by matching the first component, of type Some[_], against x: Some[t] (or x: Some[_]). Removing that match removes the warning, as do a lot of other changes. Since the first component has type Some[_], I believe it will always match against Some[_], even if I think of existentials the correct way, so I think the warning is spurious.

Necessary conditions to reproduce this warning seem to be that the scrutinee:

  • must be a tuple;
  • must have a sealed component (above, FoundNode);
  • must have a parametererized case class component (above, Some);
  • finally, the matching must include a typed pattern match on the parameterized case class component (above, : Some[_]).

I tried to alter the above example to violate any of those conditions, but that suppresses the warning; I made my experiments available here:
https://github.com/Blaisorblade/scala/blob/583184fa02586765922b6c64846669f345f2c381/test/pending/pos/ExhaustivityWarnBugReportMinimal.scala

Compiler output on the code linked above:

$ ./qbin/scalac test/pending/pos/ExhaustivityWarnBugReportMinimal.scala
test/pending/pos/ExhaustivityWarnBugReportMinimal.scala:19: warning: match may not be exhaustive.
It would fail on the following inputs: (_, FoundFilter()), (_, FoundTypeCase())
  v match {
  ^
test/pending/pos/ExhaustivityWarnBugReportMinimal.scala:22: warning: match may not be exhaustive.
It would fail on the following input: (_, _)
  v match {
  ^
test/pending/pos/ExhaustivityWarnBugReportMinimal.scala:26: warning: match may not be exhaustive.
It would fail on the following input: (_, _)
  v match {
  ^
test/pending/pos/ExhaustivityWarnBugReportMinimal.scala:32: warning: match may not be exhaustive.
It would fail on the following input: (_, _)
  vp match {
  ^
four warnings found
@scabug
Copy link
Author

scabug commented Sep 29, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6450?orig=1
Reporter: @Blaisorblade
Affected Versions: 2.10.0-M7, 2.11.6

@dwijnand
Copy link
Member

dwijnand commented Aug 2, 2020

No longer reproduces. Not worth figuring out what happened at what point in the last 8 years, IMO.

@dwijnand dwijnand closed this as completed Aug 2, 2020
@SethTisue SethTisue removed this from the Backlog milestone Aug 2, 2020
@scala scala deleted a comment from scabug Feb 5, 2021
@scala scala deleted a comment from scabug Feb 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants