Skip to content

Invalid refutable pattern warning with Tuple #15991

Closed
@Adam-Vandervorst

Description

@Adam-Vandervorst

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions