diff options
author | Lukas Rytz <lukas.rytz@typesafe.com> | 2015-02-03 12:07:37 +0100 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@typesafe.com> | 2015-02-03 12:07:37 +0100 |
commit | f79b40e08c141ae63585c5ea2fd13374bf1a0bd3 (patch) | |
tree | 80467d0a839d8cb93fe3cb044cccdfb69ad6eb94 /test | |
parent | 5d7098c629bbb7cc0ab7e74c235bd4afca3de24e (diff) | |
parent | 43818d4e5d8369387e7b315eafde01aae73acaa6 (diff) | |
download | scala-f79b40e08c141ae63585c5ea2fd13374bf1a0bd3.tar.gz scala-f79b40e08c141ae63585c5ea2fd13374bf1a0bd3.tar.bz2 scala-f79b40e08c141ae63585c5ea2fd13374bf1a0bd3.zip |
Merge pull request #4216 from som-snytt/issue/7623
SI-7623 Trailing sequence wildcard warning
Diffstat (limited to 'test')
-rw-r--r-- | test/files/neg/t7623.check | 21 | ||||
-rw-r--r-- | test/files/neg/t7623.flags | 1 | ||||
-rw-r--r-- | test/files/neg/t7623.scala | 38 |
3 files changed, 60 insertions, 0 deletions
diff --git a/test/files/neg/t7623.check b/test/files/neg/t7623.check new file mode 100644 index 0000000000..db368dd369 --- /dev/null +++ b/test/files/neg/t7623.check @@ -0,0 +1,21 @@ +t7623.scala:19: warning: A repeated case parameter or extracted sequence should be matched only by a sequence wildcard (_*). + def f = "" match { case X(s) => } + ^ +t7623.scala:21: warning: A repeated case parameter or extracted sequence should be matched only by a sequence wildcard (_*). + def g = "" match { case X(s, t) => } + ^ +t7623.scala:23: warning: A repeated case parameter or extracted sequence should be matched only by a sequence wildcard (_*). + def h = "" match { case X(s, t, u @ _*) => } + ^ +t7623.scala:9: warning: A repeated case parameter or extracted sequence should be matched only by a sequence wildcard (_*). + def f = C("") match { case C(s) => } + ^ +t7623.scala:11: warning: A repeated case parameter or extracted sequence should be matched only by a sequence wildcard (_*). + def g = C("") match { case C(s, t) => } + ^ +t7623.scala:13: warning: A repeated case parameter or extracted sequence should be matched only by a sequence wildcard (_*). + def h = C("") match { case C(s, t, u @ _*) => } + ^ +error: No warnings can be incurred under -Xfatal-warnings. +6 warnings found +one error found diff --git a/test/files/neg/t7623.flags b/test/files/neg/t7623.flags new file mode 100644 index 0000000000..74c9e38323 --- /dev/null +++ b/test/files/neg/t7623.flags @@ -0,0 +1 @@ +-Xlint:stars-align -Xfatal-warnings diff --git a/test/files/neg/t7623.scala b/test/files/neg/t7623.scala new file mode 100644 index 0000000000..5c40f37bc1 --- /dev/null +++ b/test/files/neg/t7623.scala @@ -0,0 +1,38 @@ + + +case class C(s: String, xs: Int*) + +object X { def unapplySeq(a: Any): Option[(String, Seq[Int])] = Some("", List(1,2,3)) } + +// for case classes with varargs, avoid misaligned patterns +trait Ctest { + def f = C("") match { case C(s) => } + + def g = C("") match { case C(s, t) => } + + def h = C("") match { case C(s, t, u @ _*) => } + + def ok = C("") match { case C(s, u @ _*) => } +} +// for extractors that unapplySeq: Option[(Something, Seq[_])], avoid misaligned patterns +trait Xtest { + def f = "" match { case X(s) => } + + def g = "" match { case X(s, t) => } + + def h = "" match { case X(s, t, u @ _*) => } + + def ok = "" match { case X(s, u @ _*) => } +} +// for extractors that unapplySeq: Option[Seq[_]], anything goes +trait Rtest { + val r = "(a+)".r + + def f = "" match { case r(s) => } + + def g = "" match { case r(s, t) => } + + def h = "" match { case r(s, t, u @ _*) => } + + def whatever = "" match { case r(u @ _*) => } +} |