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

Invalid refutable pattern warning with Tuple #15991

Closed
Adam-Vandervorst opened this issue Sep 7, 2022 · 2 comments · Fixed by #16051
Closed

Invalid refutable pattern warning with Tuple #15991

Adam-Vandervorst opened this issue Sep 7, 2022 · 2 comments · Fixed by #16051
Assignees
Labels
area:pattern-matching area:tuples itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@Adam-Vandervorst
Copy link

Compiler version

3.2.1-RC1-bin-20220904-b5fea82-NIGHTLY

Minimized code

While investigating , I noticed *:-tuples in unapply return raise refutable pattern warnings.

class Foo

object Foo:
//  def unapply(f: Foo): (Int, Int) = ???  // does not raise a warning
  def unapply(f: Foo): Int *: Int *: EmptyTuple = ???

@main def example =
  val Foo(x, y) = new Foo
  println(x)

Output

  val Foo(x, y) = new Foo
      ^^^^^^^^^^^^^^^^^^^
pattern binding uses refutable extractor `tuple_refutable_pattern_issue.this.Foo`

If this usage is intentional, this can be communicated by adding `: @unchecked` after the expression,
which may result in a MatchError at runtime.
This patch can be rewritten automatically under -rewrite -source 3.2-migration.

Expectation

No warning, as this can not result in a MatchError at runtime.

@Adam-Vandervorst Adam-Vandervorst added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 7, 2022
@mbovel mbovel added area:pattern-matching and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 12, 2022
@mbovel
Copy link
Member

mbovel commented Sep 12, 2022

Seems like the snippet compiles with 3.1.3 but not 3.2.0:

$ scala-cli compile --server=false --scala-version=3.1.3 refutable_pattern_tuple.scala
$ scala-cli compile --server=false --scala-version=3.2.0 refutable_pattern_tuple.scala
-- Warning: /Users/mbovel/scala-snippets/refutable_pattern_tuple.scala:7:9 -----
7 |  val Foo(x, y) = new Foo
  |      ^^^^^^^^^^^^^^^^^^^
  |pattern binding uses refutable extractor `Foo`
  |
  |If this usage is intentional, this can be communicated by adding `: @unchecked` after the expression,
  |which may result in a MatchError at runtime.
  |This patch can be rewritten automatically under -rewrite -source 3.2-migration.
1 warning found

So this is probably a regression. I am wondering if this is related to #15650.

@odersky odersky added the regression This worked in a previous version but doesn't anymore label Sep 12, 2022
@mbovel
Copy link
Member

mbovel commented Sep 12, 2022

Related: #15990.

@dwijnand dwijnand self-assigned this Sep 13, 2022
@dwijnand dwijnand linked a pull request Sep 15, 2022 that will close this issue
@Kordyjan Kordyjan added this to the 3.3.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:pattern-matching area:tuples itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants