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

False positive exhaustivity warning on parameterised prefix #8068

Closed
scabug opened this issue Dec 11, 2013 · 7 comments
Closed

False positive exhaustivity warning on parameterised prefix #8068

scabug opened this issue Dec 11, 2013 · 7 comments
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) patmat
Milestone

Comments

@scabug
Copy link

scabug commented Dec 11, 2013

This code prints false warning "match may not be exhaustive. It would fail on the following input: O"

trait K[A] {
  sealed trait T
  case class  C(x: Int) extends T
  case object O         extends T
}

object Hello {
  def f[A](k: K[A])(t: k.T) = {
    t match {
      case k.C(x) => ???
      case k.O    => ???
    }
  }
  def main(args: Array[String]) {
  }
}
@scabug
Copy link
Author

scabug commented Dec 11, 2013

Imported From: https://issues.scala-lang.org/browse/SI-8068?orig=1
Reporter: Denis Petrov (denis)
Affected Versions: 2.10.3, 2.11.0-M7, 2.11.0

@scabug
Copy link
Author

scabug commented Dec 11, 2013

@paulp said:
Foo1, no warning, Foo2, warning.

trait Foo1 {
  sealed trait T
  object O extends T
  def f(t: T) = t match { case O => 1 }
}
trait Foo2[UnusedTypeParameter] {
  sealed trait T
  object O extends T
  def f(t: T) = t match { case O => 1 }
}

@scabug
Copy link
Author

scabug commented May 21, 2014

balefrost said:
When the container is a generic class instead of a generic trait, the warning still occurs.

class Foo3[UnusedTypeParameter] {
  sealed trait T
  object O extends T
  def f(t: T) = t match { case O => 1 }
}

It also occurs if the type parameter is referenced

class Foo4[A] {
  sealed trait T
  object O extends T
  def f[A](t: T, v: A) = t match { case O => v }
}

@scabug
Copy link
Author

scabug commented May 24, 2014

balefrost said:
Appears to be fixed in 2.11.1!

@scabug
Copy link
Author

scabug commented Jan 3, 2015

@gbasler said (edited on Jan 3, 2015 6:49:24 PM UTC):
@adriaanm this seems to be fixed in 2.11.5-SNAPSHOT... should I can create a pr with a regression test for this?

@scabug scabug added the patmat label Apr 7, 2017
@adriaanm adriaanm removed their assignment Sep 28, 2018
@SethTisue SethTisue changed the title false warning "match may not be exhaustive false warning "match may not be exhaustive" Jul 3, 2019
@SethTisue
Copy link
Member

In 2.13.0, only the original code still warns.

@dwijnand dwijnand self-assigned this Feb 4, 2021
@dwijnand dwijnand changed the title false warning "match may not be exhaustive" False positive exhaustivity warning on parameterised prefix Nov 11, 2021
@dwijnand dwijnand removed their assignment Nov 11, 2021
@SethTisue SethTisue added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Aug 25, 2022
@SethTisue SethTisue added this to the 2.13.8 milestone Aug 25, 2022
@SethTisue
Copy link
Member

Doesn't warn on 2.13.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) patmat
Projects
None yet
Development

No branches or pull requests

4 participants