summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2007-09-01 09:27:17 +0000
committerBurak Emir <emir@epfl.ch>2007-09-01 09:27:17 +0000
commit6ac1007149f105a1f96bfa750e6a48c42aff0c48 (patch)
treee2b7cbac596081c82e370febacb5692ba28f94b1
parent8af1dfade7e0fafcbe7adb4dbea14d734d9b8dea (diff)
downloadscala-6ac1007149f105a1f96bfa750e6a48c42aff0c48.tar.gz
scala-6ac1007149f105a1f96bfa750e6a48c42aff0c48.tar.bz2
scala-6ac1007149f105a1f96bfa750e6a48c42aff0c48.zip
fixed #37
-rw-r--r--src/compiler/scala/tools/nsc/matching/ParallelMatching.scala53
-rw-r--r--src/compiler/scala/tools/nsc/matching/PatternNodes.scala2
-rw-r--r--test/files/run/patmatnew.check2
-rw-r--r--test/files/run/patmatnew.scala13
4 files changed, 44 insertions, 26 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
index 31ec804325..ecbf265fdf 100644
--- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
+++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
@@ -732,11 +732,11 @@ trait ParallelMatching {
(p::ms, (j, dummies)::ss, rs);
case q @ Typed(pp,_) if (patternType_wrtEquals(pat.tpe) <:< headPatternType) =>
- //Console.println("current pattern is same or *more* specific")
- ({if(pat.tpe =:= headPatternType /*never true for <equals>*/) EmptyTree else q}::ms, (j, dummies)::ss, rs);
+ //Console.println("current pattern [Typed] is same or *more* specific")
+ ({if(pat.tpe =:= headPatternType /*never true for <equals>*/) pp/*EmptyTree*/ else q}::ms, (j, dummies)::ss, rs);
case qq if (patternType_wrtEquals(pat.tpe) <:< headPatternType) && !isDefaultPattern(pat) =>
- //Console.println("current pattern is same or *more* specific")
+ //Console.println("current pattern [ ... ] is same or *more* specific")
({if(pat.tpe =:= headPatternType /*never true for <equals>*/) EmptyTree else pat}::ms, (j,subpatterns(pat))::ss, rs);
case _ if (headPatternType <:< pat.tpe /*never true for <equals>*/) || isDefaultPattern(pat) =>
@@ -770,7 +770,7 @@ trait ParallelMatching {
casted.setFlag(symtab.Flags.TRANS_FLAG)
// succeeding => transition to translate(subsumed) (taking into account more specific)
val nmatrix = {
- var ntemps = if(isCaseClass(casted.tpe)) casted.caseFieldAccessors map {
+ var ntemps = if(isCaseHead /*for annontated type, isCaseHead == false but isClass(casted.tpe) == true*/) casted.caseFieldAccessors map {
meth =>
val ctemp = newVar(scrutinee.pos, casted.tpe.memberType(meth).resultType)
if(scrutinee.hasFlag(symtab.Flags.TRANS_FLAG))
@@ -854,24 +854,15 @@ trait ParallelMatching {
*/
final def repToTree(r: Rep)(implicit theOwner: Symbol, failTree: Tree, rep: RepFactory): Tree = {
r.applyRule.tree
- /*
- rep.applyRule match {
- case r : ErrorRule => r.tree
-
- case vr: VariableRule => vr.tree
-
- case mc: MixCases => mc.tree
-
- case ml: MixLiterals => ml.tree
-
- case me: MixEquals => me.tree
-
- case mm: MixTypes => mm.tree
-
- case mu: MixUnapply => mu.tree
-
- }
- */
+ /*r.applyRule match {
+ case r : ErrorRule => Console.println("R1"); r.tree
+ case vr: VariableRule => Console.println("R2"); vr.tree
+ case mc: MixCases => Console.println("R3"); mc.tree
+ case ml: MixLiterals => Console.println("R4"); ml.tree
+ case me: MixEquals => Console.println("R5"); me.tree
+ case mm: MixTypes => Console.println("R6"); mm.tree
+ case mu: MixUnapply => Console.println("R7"); mu.tree
+ }*/
}
/** subst: the bindings so far */
@@ -907,6 +898,7 @@ trait ParallelMatching {
this.vss = vss
this.reached64 = if(targets.length < 64) new Set64 else null
//Console.println("targets: "+targets)
+ //Console.println("vss: "+vss)
//Console.print("labels: "); {for(s<-labels) Console.print({if(s ne null) {s} else "_"}+",")}
return make(temp, row)
}
@@ -989,8 +981,10 @@ trait ParallelMatching {
val argts = new ListBuffer[Type] // types of
var vrev: List[Symbol] = Nil
var vdefs:List[Tree] = Nil
+ //Console.println("vss = "+vss(bx))
val it = vss(bx).elements; while(it.hasNext) {
val v = it.next
+ //Console.println("v = "+v)
val substv = subst(v)
if(substv ne null) {// might be bound elsewhere ( see `x @ unapply' )
vrev = v :: vrev
@@ -1079,7 +1073,16 @@ trait ParallelMatching {
//Console.println("opats.head = "+opats.head.getClass)
val (vars,strippedPat) = strip(opat)
val vs = vars.toList
- strippedPat match {
+ def handle(prepat:Tree): Unit = prepat match {
+
+ /* annotations do not make sense on pattern
+ case Typed(p, tpt) if prepat.tpe.isInstanceOf[AnnotatedType] =>
+ Console.println("HELLO")
+ Console.println("p ="+p)
+ Console.println("p.tpe ="+p.tpe)
+ opat = makeBind(vs,p)
+ handle(p)
+ */
case p @ Alternative(ps) =>
if(indexOfAlternative == -1) {
unchanged = false
@@ -1216,6 +1219,8 @@ trait ParallelMatching {
assert(false) // inactive, @see PatternMatchers::isImplemented
}
+ handle(strippedPat)
+ //Console.println("!!added "+pats.head+":"+pats.head.tpe)
opats = opats.tail
j += 1
}
@@ -1402,6 +1407,8 @@ trait ParallelMatching {
var cs = cases; while (cs ne Nil) cs.head match { // stash away pvars and bodies for later
case CaseDef(pat,g,b) =>
+ //Console.println("pat::"+pat)
+ //Console.println("dv ::"+definedVars(pat))
vss += definedVars(pat)
targets += b
row += Row(List(pat), NoBinding, g, bx)
diff --git a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
index bc9c359502..59969ed1b7 100644
--- a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
+++ b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
@@ -172,7 +172,7 @@ trait PatternNodes { self: transform.ExplicitOuter =>
case Ident(_) => ;
case Literal(_) => ;
case Select(_,_) => ;
- case Typed(p,_) => ; // definedVars1(p) //shouldn't have, because x @ (_:T)
+ case Typed(p,_) => definedVars1(p) //otherwise x @ (_:T)
case UnApply(_,args) => definedVars2(args)
// regexp specific
diff --git a/test/files/run/patmatnew.check b/test/files/run/patmatnew.check
new file mode 100644
index 0000000000..0747cddefb
--- /dev/null
+++ b/test/files/run/patmatnew.check
@@ -0,0 +1,2 @@
+warning: there were unchecked warnings; re-run with -unchecked for details
+one warning found
diff --git a/test/files/run/patmatnew.scala b/test/files/run/patmatnew.scala
index 09b12f710c..c8ca9c19cb 100644
--- a/test/files/run/patmatnew.scala
+++ b/test/files/run/patmatnew.scala
@@ -42,7 +42,8 @@ object Test extends TestConsoleMain {
Bug1093,
Bug1094,
ClassDefInGuard,
- Ticket_2
+ Ticket2,
+ Ticket37
)
class Foo(j:Int) {
@@ -578,7 +579,7 @@ object Test extends TestConsoleMain {
}
}
- object Ticket_2 extends TestCase("#2") { override def runTest {
+ object Ticket2 extends TestCase("#2") { override def runTest {
val o1 = new Outer_2; val o2 = new Outer_2; val x: Any = o1.Foo(1, 2); val y: Any = o2.Foo(1, 2)
assertFalse("equals test returns true (but should not)", x equals y)
assertTrue("match enters wrong case", x match {
@@ -588,6 +589,14 @@ object Test extends TestConsoleMain {
})
}}
+ // #37
+
+ object Ticket37 extends TestCase("#37") {
+ def foo() {}
+ val (a,b):(int,int) = { foo(); (2,3) }
+ override def runTest { assertEquals(this.a, 2) }
+ }
+
}