summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2015-11-25 14:53:50 +1000
committerJason Zaugg <jzaugg@gmail.com>2015-11-25 14:54:05 +1000
commite07d62cdefd5b01734692fc549521e562984ccb0 (patch)
treeca9c8204ee7c13278a900a9c6d08293167d4bc23 /test
parent4e4709a3b0dd869b98c1a8d854f4a54145ade2ff (diff)
downloadscala-e07d62cdefd5b01734692fc549521e562984ccb0.tar.gz
scala-e07d62cdefd5b01734692fc549521e562984ccb0.tar.bz2
scala-e07d62cdefd5b01734692fc549521e562984ccb0.zip
SI-9567 Fix pattern match on 23+ param, method local case class
Typechecking constructor patterns of method local case classes was only working because of the existence of the unapply method in the companion, which is used if navigation to the case class companion object fails. We now support defintion of, and pattern matching on, case classes with more than 22 parameters. These have no `unapply` method in the companion, as we don't have a large enough tuple type to return. So for such case classes, the fallback that we inadvertently relied on would no longer save us, and we'd end up with a compile error advising that the identifier in the constructor pattern was neither a case class nor an extractor. This is due to the propensity of `Symbol#companionXxx` to return `NoSymbol` when in the midst of typechecking. That method should only be relied upon after typechecking. During typechecking, `Namers#companionSymbolOf` should be used instead, which looks in the scopes of enclosing contexts for symbol companionship. That's what I've done in this commit.
Diffstat (limited to 'test')
-rw-r--r--test/files/run/t9567.scala18
-rw-r--r--test/files/run/t9567b.scala19
2 files changed, 37 insertions, 0 deletions
diff --git a/test/files/run/t9567.scala b/test/files/run/t9567.scala
new file mode 100644
index 0000000000..69896b8650
--- /dev/null
+++ b/test/files/run/t9567.scala
@@ -0,0 +1,18 @@
+object Test {
+ def testMethodLocalCaseClass {
+ case class MethodLocalWide(
+ f01: Int, f02: Int, f03: Int, f04: Int, f05: Int, f06: Int, f07: Int, f08: Int, f09: Int, f10: Int,
+ f11: Int, f12: Int, f13: Int, f14: Int, f15: Int, f16: Int, f17: Int, f18: Int, f19: Int, f20: Int,
+ f21: Int, f22: Int, f23: Int)
+
+ val instance = MethodLocalWide(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+ val result = instance match {
+ case MethodLocalWide(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) => true
+ case _ => false
+ }
+ assert(result)
+ }
+ def main(args: Array[String]) {
+ testMethodLocalCaseClass
+ }
+}
diff --git a/test/files/run/t9567b.scala b/test/files/run/t9567b.scala
new file mode 100644
index 0000000000..88cef0a60e
--- /dev/null
+++ b/test/files/run/t9567b.scala
@@ -0,0 +1,19 @@
+object Test {
+ def testMethodLocalCaseClass {
+ object MethodLocalWide
+ case class MethodLocalWide(
+ f01: Int, f02: Int, f03: Int, f04: Int, f05: Int, f06: Int, f07: Int, f08: Int, f09: Int, f10: Int,
+ f11: Int, f12: Int, f13: Int, f14: Int, f15: Int, f16: Int, f17: Int, f18: Int, f19: Int, f20: Int,
+ f21: Int, f22: Int, f23: Int)
+
+ val instance = MethodLocalWide(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+ val result = instance match {
+ case MethodLocalWide(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) => true
+ case _ => false
+ }
+ assert(result)
+ }
+ def main(args: Array[String]) {
+ testMethodLocalCaseClass
+ }
+}