summaryrefslogtreecommitdiff
path: root/test/files/run/t9567c.scala
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
commit4e4709a3b0dd869b98c1a8d854f4a54145ade2ff (patch)
tree36d48ff77e336f5e28d95eac31e2698cb665be66 /test/files/run/t9567c.scala
parent2890f0b767948dd9a0953b1e669e85dbd45ec0a7 (diff)
downloadscala-4e4709a3b0dd869b98c1a8d854f4a54145ade2ff.tar.gz
scala-4e4709a3b0dd869b98c1a8d854f4a54145ade2ff.tar.bz2
scala-4e4709a3b0dd869b98c1a8d854f4a54145ade2ff.zip
SI-9567 Fix latent bugs in patmat's reasoning about mutability
Under -optimize, the pattern matcher tries to avoid local variables in favour of directly accessing to non-var case class accessors. However, the code that analysed the patterns failed to account properly for repeated parameters, which could either lead to a compiler crash (when assuming that the n-th subpattern must have a corresponding param accessor), or could lead to a correctness problem (when failing to eagerly the bound elements from the sequence.) The test case that tried to cover seems only to have been working because of a separate bug (the primary subject of SI-9567) related to method-local case classes: they were treated during typechecking as extractors, rather than native case classes. The subsequent commit will fix that problem, but first we must pave the way with this commit that emits local vals for bound elements of case class repeated params.
Diffstat (limited to 'test/files/run/t9567c.scala')
-rw-r--r--test/files/run/t9567c.scala29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/files/run/t9567c.scala b/test/files/run/t9567c.scala
new file mode 100644
index 0000000000..560bea8821
--- /dev/null
+++ b/test/files/run/t9567c.scala
@@ -0,0 +1,29 @@
+case class CaseSequenceTopLevel(as: Int*)
+
+object Test {
+ def main(args: Array[String]): Unit = {
+
+ val buffer1 = collection.mutable.Buffer(0, 0)
+ CaseSequenceTopLevel(buffer1: _*) match {
+ case CaseSequenceTopLevel(_, i) =>
+ buffer1(1) = 1
+ assert(i == 0, i) // fails in 2.11.7 -optimize
+ }
+
+ case class CaseSequence(as: Int*)
+ val buffer2 = collection.mutable.Buffer(0, 0)
+ CaseSequence(buffer2: _*) match {
+ case CaseSequence(_, i) =>
+ buffer2(1) = 1
+ assert(i == 0, i)
+ }
+
+ case class CaseSequenceWithVar(var x: Any, as: Int*)
+ val buffer3 = collection.mutable.Buffer(0, 0)
+ CaseSequenceWithVar("", buffer3: _*) match {
+ case CaseSequenceWithVar(_, _, i) => // crashes in 2.11.7
+ buffer2(1) = 1
+ assert(i == 0, i)
+ }
+ }
+}