At the very least, change the last line: case other => () => { println("not sure what's going on " + other); Empty } and tell us what it prints.
– Landei Jun 13 at 11:58 1 I guess because it was not an answer; I only added it as an answer for the formatting and so that the OP could alter their question and then I could conceivably change my answer based on it. I agree; a harsh downvote – oxbow_lakes Jun 13 at 12:18 I personally don't like the 'feature' of Scala's lower case names in match. I would rather write case a:Any => // do something with a.
– Jus12 Jun 13 at 14:31 @Landei, This response is more of a comment rather than an "answer" (not the downvoter). – notnoop Jun 14 at 21:06.
I just typed up an example which seems to be the same scenario you've got in your code, and it works as expected in Scala 2.9: case class Foo(x:String) val bar = Foo("bar") bar match { case x:Foo if false => println("Impossible") case Foo(x) => println("Expected: " + x) case _ => println("Should not happen") } Which outputs Expected: bar See if you can reproduce the bug in a self-contained example like this, so maybe we (or if it is a bug, the Scala Dev Team, can figure out what is going wrong :) Note: Seems like I misread your question the first time, sorry for that. I'm not going to delete this part anyway, because it might be helpful to someone else. When using pattern matching, the first case-statement that matches will be executed, and after that, the match is complete and all other case statements will be ignored!
Your problem here is, that the first statement case req:Req => matches every instance of Req. After matching the first statement and executing its code, Scala just jumps out of the match expression because it is finished. The second case-statement would match, but it is never executed for any given instance of Req because the first one matches.As far as I remember, this is known as shadowing a case statement.
So move your second case statement before the first one, and you should be fine. Note that this is why in pattern matching, the more specific match cases need to come first and the more general case statements have to go last.
1 I suspect that you did not read it wrong ... that it is an ordering problem, at least ... but it's hard to tell, as the OP has made so many assumptions and left out so much critical information. – Jim Balter Jun 13 at 0:14 Why the downvote? ... – x3ro Jun 14 at 11:15 I suspect because the answer contains couple of inaccuracies: the question didn't have an unconditioned case matching all Req, except for the case so there is no ordering issue here; the updated revision is more of a comment (e.g."See if you can reproduce the bug in a self-contained example like this") than an actual answer.
I was able to reproduce the problem in my commend. (not the downvoter). – notnoop Jun 14 at 21:20 Yes, I in the note that I think that I misread the question, and that I didn't want to delete it because it might be helpful for someone else.
Then I tried to give a self-contained example of what I thought was a reproduction of the example given by the question creator, which I merely did in the answer (instead of a comment, which also would've been badly formatted) to help the question creator to modify it to recreate the problem. I don't really see how my effort deserves a down vote, because it couldn't have been unhelpful, imo. – x3ro Jun 14 at 21:44.
This is indeed the bug you are referencing in the Scala bug tracker. Req is a non-case class with a companion extractor methods, so the bug manifests itself here. The workaround you introduced seems fine.
For those interested, here is a sample case where the bug manifests itself: class Sample(val a: String) object Sample { def apply(a: String) = new Sample(a) def unapply(s: Sample) = Option(s. A) } val s = new Sample("a") val r = s match { case n: Sample if false => "Wrong 1: " + n case Sample(_) => "Yay" case n => "Wrong 2: " + n } println("Found " + r) assert(r == "Yay").
In your case the following works: case s:Sample => "Yay" // s. A to access a – Jus12 Jun 14 at 22:27.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.