Thanks for the great example, I tried, and it works as I expected. It's nice to see someone understand the nature of the problem. However, I think I should have noted the problem with Lift, since I use the Lift framework, and this is where the problem is (still) (although I still think this might be due to extraction in scala) . Since I donβt want to play the entire Lift installation here, since there will be too much code, I hope that someone familiar with the Lift will be able to understand what I am doing here. I deleted more variables to make it easier (for some) to see the problem:
lazy val dispatch: LiftRules.DispatchPF = { // Explicitly setting guard to false to trigger the scenario case req: Req if false => () => println("shouldn't match"); Empty // This should match since previous case will never match case Req(_, _, _) => () => println("should match"); Empty // This is actually called... case _ => () => println("shouldn't reach here"); Empty }
As before, if I comment on the first case, the second case will be as expected.
For those who are interested, a simple workaround is:
lazy val dispatch: LiftRules.DispatchPF = { case req: Req => { if (false) { // Obviously you put something more useful than false here... () => println("shouldn't match"); Empty } else req match { // This matches case Req(_, _, _) => () => println("should match"); Empty // This is now never called case other => () => println("shouldn't reach here"); Empty } } }
ORIGINAL MAIL
I'm new to scala, so I may be doing something wrong here, but I have an expression that matches the pattern, which seems to be missing. Here is the code:
lazy val dispatch: LiftRules.DispatchPF = { // Explicitly setting guard to false to trigger the scenario case req: Req if false => () => Full(...) // This should match since previous case will never match case Req("api" :: "test" :: Nil, suffix, GetRequest) => () => Full(...) // This is actually called... case _ => () => println("not sure what going on"); Empty }
If I select the first case expression, everything will work as expected. I am tempted to think that this is a mistake ( https://issues.scala-lang.org/browse/SI-2337 ), but does anyone know of a workaround?