diff options
author | Paul Phillips <paulp@improving.org> | 2013-12-15 18:28:03 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-12-15 18:28:03 -0800 |
commit | def46a9d448c4ee84eea48694a65af438370f940 (patch) | |
tree | 43ff702f2988f0d88780c92394762991c4bb8764 /test/files/neg | |
parent | 11bfa25e37d32f4017d5c04b4899b1bdfbd95e06 (diff) | |
download | scala-def46a9d448c4ee84eea48694a65af438370f940.tar.gz scala-def46a9d448c4ee84eea48694a65af438370f940.tar.bz2 scala-def46a9d448c4ee84eea48694a65af438370f940.zip |
SI-7850 CCE in patmat with invalid isEmpty.
Name-based pattern matcher needed some hardening against
unapply methods with the right name but wrong types. Only
isEmpty methods which return Boolean are acceptable.
Catching it directly rather than indirectly also allowed
for better error messages.
Diffstat (limited to 'test/files/neg')
-rw-r--r-- | test/files/neg/t4425.check | 6 | ||||
-rw-r--r-- | test/files/neg/t4425b.check | 12 | ||||
-rw-r--r-- | test/files/neg/t7850.check | 7 | ||||
-rw-r--r-- | test/files/neg/t7850.scala | 16 |
4 files changed, 32 insertions, 9 deletions
diff --git a/test/files/neg/t4425.check b/test/files/neg/t4425.check index 95b88a6b3d..00006c08f0 100644 --- a/test/files/neg/t4425.check +++ b/test/files/neg/t4425.check @@ -1,12 +1,12 @@ -t4425.scala:3: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425.scala:3: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: Int)(y: Option[Int]): None.type exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list 42 match { case _ X _ => () } ^ -t4425.scala:8: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425.scala:8: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: Int)(y: Int): Some[(Int, Int)] exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list 42 match { case _ X _ => () } ^ -t4425.scala:13: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425.scala:13: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: String)(y: String): Some[(Int, Int)] exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list "" match { case _ X _ => () } ^ diff --git a/test/files/neg/t4425b.check b/test/files/neg/t4425b.check index ae7b469d52..8418b4fd12 100644 --- a/test/files/neg/t4425b.check +++ b/test/files/neg/t4425b.check @@ -1,24 +1,24 @@ -t4425b.scala:5: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425b.scala:5: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list println( "" match { case _ X _ => "ok" ; case _ => "fail" }) ^ -t4425b.scala:6: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425b.scala:6: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list println((X: Any) match { case _ X _ => "ok" ; case _ => "fail" }) ^ -t4425b.scala:7: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425b.scala:7: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list println( "" match { case X(_) => "ok" ; case _ => "fail" }) ^ -t4425b.scala:8: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425b.scala:8: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list println((X: Any) match { case X(_) => "ok" ; case _ => "fail" }) ^ -t4425b.scala:9: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425b.scala:9: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list println( "" match { case X(_, _) => "ok" ; case _ => "fail" }) ^ -t4425b.scala:10: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425b.scala:10: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list println((X: Any) match { case X(_, _) => "ok" ; case _ => "fail" }) ^ diff --git a/test/files/neg/t7850.check b/test/files/neg/t7850.check new file mode 100644 index 0000000000..317be2bbce --- /dev/null +++ b/test/files/neg/t7850.check @@ -0,0 +1,7 @@ +t7850.scala:11: error: an unapply result must have a member `def isEmpty: Boolean (found: def isEmpty: Casey) + val Casey(x1) = new Casey(1) + ^ +t7850.scala:12: error: an unapply result must have a member `def isEmpty: Boolean + val Dingy(x2) = new Dingy(1) + ^ +two errors found diff --git a/test/files/neg/t7850.scala b/test/files/neg/t7850.scala new file mode 100644 index 0000000000..04edad82b5 --- /dev/null +++ b/test/files/neg/t7850.scala @@ -0,0 +1,16 @@ +// isEmpty returns non-boolean +class Casey(a: Int) { def isEmpty = this; def get = this } +object Casey { def unapply(a: Casey) = a } + +// no isEmpty method at all +class Dingy(a: Int) { def get = this } +object Dingy { def unapply(a: Dingy) = a } + +object Test { + def main(args: Array[String]) { + val Casey(x1) = new Casey(1) + val Dingy(x2) = new Dingy(1) + println(s"$x1 $x2") + } +} + |