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

Wrong attempt to rebind a wildcard sequence compiles and results in runtime CCE #8715

Closed
som-snytt opened this issue Apr 13, 2020 · 0 comments
Assignees

Comments

@som-snytt
Copy link
Contributor

Minimized code

@main
def f = List(42) match { case List(xs @ (ys: _*)) => xs }

Output

$ ~/bin/dotc noseq.scala
-- [E029] Pattern Match Exhaustivity Warning: noseq.scala:3:12 -----------------
3 |def f = List(42) match { case List(xs @ (ys: _*)) => xs }
  |        ^^^^^^^^
  |        match may not be exhaustive.
  |
  |        It would fail on pattern case: List(_, _: _*), Nil

longer explanation available when compiling with `-explain`
one warning found
$ ~/bin/dotr f
Exception in thread "main" java.lang.ClassCastException: class scala.collection.immutable.$colon$colon cannot be cast to class java.lang.Integer (scala.collection.immutable.$colon$colon is in unnamed module of loader 'app'; java.lang.Integer is in module java.base of loader 'bootstrap')
        at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:99)
        at noseq$package$.f(noseq.scala:3)
        at f.main(noseq.scala:2)

Expectation

scala 2.13.1> def f = List(42) match { case List(xs @ (ys @ _*)) => xs }
                                                              ^
              error: bad simple pattern: bad use of _* (sequence pattern not allowed)

The exhaustivity warning is also misguided, also in the correct case.

@liufengyun liufengyun self-assigned this Apr 14, 2020
liufengyun added a commit to dotty-staging/dotty that referenced this issue Apr 16, 2020
Previously we didn't check that _* is indeed the last argument,
checking for ")" is not enough, as ")" may be the closing parenthsis
of a nested pattern.
odersky added a commit to dotty-staging/dotty that referenced this issue Apr 20, 2020
Previously we didn't check that _* is indeed the last argument,
checking for ")" is not enough, as ")" may be the closing parenthesis
of a nested pattern.
odersky added a commit to dotty-staging/dotty that referenced this issue Apr 20, 2020
liufengyun added a commit that referenced this issue Apr 20, 2020
Fix #8715: enforce syntax for _* (alternate version)
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.

2 participants