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

Binding name to sequence wildcard induces exhaustivity warning #8757

Closed
som-snytt opened this issue Apr 21, 2020 · 3 comments · Fixed by #8820
Closed

Binding name to sequence wildcard induces exhaustivity warning #8757

som-snytt opened this issue Apr 21, 2020 · 3 comments · Fixed by #8820

Comments

@som-snytt
Copy link
Contributor

Minimized code

scala> sealed trait T ; case class C(x: Int) extends T
// defined trait T
// defined case class C

scala> (C(42): T) match { case C(42) => }
1 |(C(42): T) match { case C(42) => }
  | ^^^^^^^^
  | match may not be exhaustive.
  |
  | It would fail on pattern case: C(_)

scala> (C(42): T) match { case C(_) => }

scala> (C(42): T) match { case C(x) => }

scala> sealed trait T ; case class C(x: Int*) extends T
// defined trait T
// defined case class C

scala> (C(42): T) match { case C(42) => }
1 |(C(42): T) match { case C(42) => }
  | ^^^^^^^^
  | match may not be exhaustive.
  |
  | It would fail on pattern case: C(_, _: _*), C(_, _, _: _*), C()

scala> (C(42): T) match { case C(xs: _*) => }
1 |(C(42): T) match { case C(xs: _*) => }
  | ^^^^^^^^
  | match may not be exhaustive.
  |
  | It would fail on pattern case: C(_: _*)

scala> (C(42): T) match { case C(_: _*) => }

scala>                                                         

Output

scala> (C(42): T) match { case C(xs: _*) => }
1 |(C(42): T) match { case C(xs: _*) => }
  | ^^^^^^^^
  | match may not be exhaustive.
  |
  | It would fail on pattern case: C(_: _*)

Expectation

Expect case C(xs: _*) is as exhaustive as case C(_: _*).

Observed at #8715

@odersky
Copy link
Contributor

odersky commented Apr 27, 2020

Fixed by #8753

@odersky odersky closed this as completed Apr 27, 2020
@som-snytt
Copy link
Contributor Author

I see the same behavior on head. I'll update again if I have more info.

sbt:dotty> dotc sandbox/t8757.scala
[warn] Multiple main classes detected.  Run 'show discoveredMainClasses' to see the list
[info] running (fork) dotty.tools.dotc.Main -classpath /Users/andrew/.coursier/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.2/scala-library-2.13.2.jar:/Users/andrew/workspace/dotty/library/../out/bootstrap/dotty-library-bootstrapped/scala-0.25/dotty-library_0.25-0.25.0-bin-SNAPSHOT.jar sandbox/t8757.scala
-- [E029] Pattern Match Exhaustivity Warning: sandbox/t8757.scala:3:17 ---------
3 |def f(): Unit = (C(42): T) match { case C(xs: _*) => }
  |                 ^^^^^^^^
  |                 match may not be exhaustive.
  |
  |                 It would fail on pattern case: C(_: _*)

longer explanation available when compiling with `-explain`
1 warning found
[success] Total time: 5 s, completed Apr 28, 2020, 12:34:06 AM
sbt:dotty> [info] shutting down sbt server
➜  dotty git:(review/exhausted) ✗ cat sandbox/t8757.scala
sealed trait T ; case class C(xs: Int*) extends T

def f(): Unit = (C(42): T) match { case C(xs: _*) => }
def g(): Unit = (C(42): T) match { case C(_: _*) => }

@liufengyun liufengyun self-assigned this Apr 28, 2020
@liufengyun
Copy link
Contributor

This one is not fixed.

@liufengyun liufengyun reopened this Apr 28, 2020
liufengyun added a commit to dotty-staging/dotty that referenced this issue Apr 28, 2020
smarter added a commit that referenced this issue Apr 28, 2020
Fix #8757: check wildcard star patterns by tree instead of type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants