From 692372ce1d82d0ba41461b9539fdc85238477464 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sun, 13 Jan 2013 12:36:36 +0100 Subject: SI-6675 -Xlint arity enforcement for extractors Extractor Patterns changed in 2.10.0 to implement the letter of the spec, which allows a single binding to capture an entire TupleN. But this can hide arity mismatches, especially if the case body uses the bound value as an `Any`. This change warns when this happens under -Xlint. --- test/files/neg/t6675.check | 4 ++++ test/files/neg/t6675.flags | 1 + test/files/neg/t6675.scala | 13 +++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 test/files/neg/t6675.check create mode 100644 test/files/neg/t6675.flags create mode 100644 test/files/neg/t6675.scala (limited to 'test') diff --git a/test/files/neg/t6675.check b/test/files/neg/t6675.check new file mode 100644 index 0000000000..7b271de213 --- /dev/null +++ b/test/files/neg/t6675.check @@ -0,0 +1,4 @@ +t6675.scala:10: error: extractor pattern binds a single value to a Product3 of type (Int, Int, Int) + "" match { case X(b) => b } // should warn under -Xlint. Not an error because of SI-6111 + ^ +one error found diff --git a/test/files/neg/t6675.flags b/test/files/neg/t6675.flags new file mode 100644 index 0000000000..e93641e931 --- /dev/null +++ b/test/files/neg/t6675.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings \ No newline at end of file diff --git a/test/files/neg/t6675.scala b/test/files/neg/t6675.scala new file mode 100644 index 0000000000..4d500b77ba --- /dev/null +++ b/test/files/neg/t6675.scala @@ -0,0 +1,13 @@ +object X { + def unapply(s: String): Option[(Int,Int,Int)] = Some((1,2,3)) +} + +object Y { + def unapplySeq(s: String): Option[Seq[(Int,Int,Int)]] = Some(Seq((1,2,3))) +} + +object Test { + "" match { case X(b) => b } // should warn under -Xlint. Not an error because of SI-6111 + + "" match { case Y(b) => b } // no warning +} -- cgit v1.2.3