summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/matching/ParallelMatching.scala8
-rw-r--r--test/files/run/patmatnew.scala51
2 files changed, 50 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
index 96eecf69b8..72b8645e7e 100644
--- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
+++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
@@ -75,7 +75,7 @@ trait ParallelMatching {
}
/*
DBG("/// MixtureRule("+scrutinee.name+":"+scrutinee.tpe+","+column+", rep = ")
- DBG(rest)
+ DBG(rest.toString)
DBG(")///")
*/
if(isEqualsPattern(column.head.tpe)) { DBG("\n%%% MixEquals");
@@ -572,12 +572,14 @@ trait ParallelMatching {
case TypeRef(_,_,List(SingleType(pre,sym))) =>
gen.mkAttributedRef(pre,sym)
}
+ val nsuccFst = rest.row.head match { case Row(pats,bnd,g,b) => Row(EmptyTree::pats,bnd,g,b) }
+ val nsuccRow = nsuccFst :: (column.tail.zip(rest.row.tail) map { case (p, Row(pats,bnd,g,b)) => Row(p::pats,bnd,g,b) })
+ val nsucc = Rep(scrutinee :: rest.temp, nsuccRow)
val nfail = repWithoutHead(column,rest)
- return (typed{ Equals(Ident(scrutinee) setType scrutinee.tpe, vlue) }, rest, nfail)
+ return (typed{ Equals(Ident(scrutinee) setType scrutinee.tpe, vlue) }, nsucc, nfail)
}
final def tree(implicit handleOuter: Tree=>Tree, theOwner: Symbol, failTree: Tree) = {
- handleOuter(Ident("GAGA"))
val (cond,srep,frep) = this.getTransition
val cond2 = try{
typed { handleOuter(cond) }
diff --git a/test/files/run/patmatnew.scala b/test/files/run/patmatnew.scala
index a28f94c539..ee0d620d21 100644
--- a/test/files/run/patmatnew.scala
+++ b/test/files/run/patmatnew.scala
@@ -26,6 +26,7 @@ object Test extends TestConsoleMain {
def suite = new TestSuite(
new TestSimpleIntSwitch,
new SimpleUnapply,
+ SeqUnapply,
new Test717,
new TestGuards,
TestEqualsPatternOpt,
@@ -44,8 +45,26 @@ object Test extends TestConsoleMain {
List((1,2)).head match {
case kv @ Pair(key, _) => kv.toString + " " + key.toString
}
+
+
+ }
+ }
+
+ object SeqUnapply extends TestCase("seqUnapply") {
+ case class SFB(i:int,xs:List[Int])
+ override def runTest() {
+ List(1,2) match {
+ case List(1) => assert(false, "wrong case")
+ case List(1,2,xs @ _*) => assert(xs.isEmpty, "not empty")
+ case Nil => assert(false, "wrong case")
+ }
+ SFB(1,List(1)) match {
+ case SFB(_,List(x)) => assert(x==1)
+ case SFB(_,_) => assert(false)
+ }
}
}
+
class TestSimpleIntSwitch extends TestCase("SimpleIntSwitch") {
override def runTest() = {
assertEquals("s1", 1, 1 match {
@@ -279,12 +298,6 @@ object Test extends TestConsoleMain {
case _ => 4
}
- def i = List(1,2) match {
- case List(1) =>
- case List(1,2,xs @ _*) =>
- case Nil =>
- }
-
def j = (List[Int](), List[Int](1)) match {
case (Nil, _) => 'a'
case (_, Nil) => 'b'
@@ -345,6 +358,32 @@ object Test extends TestConsoleMain {
}
}
*/
+ object TestIfOpt { //compile-only "test EqualsPatternClass in combination with MixTypes opt, bug #1278"
+ trait Token {
+ val offset : Int
+ def matching : Option[Token]
+ }
+ def go(tok : Token) = tok.matching match {
+ case Some(other) if true => Some(other)
+ case _ if true => tok.matching match {
+ case Some(other) => Some(other)
+ case _ => None
+ }
+ }
+ }
+
+ object Go { // bug #1277 compile-only
+ trait Core { def next : Position = null }
+ trait Dir
+ val NEXT = new Dir{}
+
+ trait Position extends Core
+
+ (null:Core,null:Dir) match {
+ case (_, NEXT) if true => false // no matter whether NEXT test succeed, cannot throw column because of guard
+ case (at2:Position,dir) => true
+ }
+ }
}