scala3
scala3 copied to clipboard
Invalid refutable pattern warning with Tuple
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.
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 https://github.com/lampepfl/dotty/issues/15650.
Related: https://github.com/lampepfl/dotty/issues/15990.