Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6040643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:32:39+00:00 2026-05-23T06:32:39+00:00

Thanks for the excellent example, I tried it and it works as I expected.

  • 0

Thanks for the excellent example, I tried it and it works as I expected. Nice to see someone understood the nature of the problem. However, I think I should have tagged the problem with Lift as I’m using the Lift framework and that is where this problem is (still) occurring (although I still think it might be related to extraction in scala). Since I don’t want to reproduce the entire Lift setup here as it will be too much code, I’m going to hope someone familiar with Lift can understand what I’m doing here. I’ve removed more variables so it might be 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 out the first case the second case is matched as expected.

For those 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 POST

I’m new to scala, so I may be doing something wrong here, but I have a pattern matching expression that seems to be skipped over. Here’s 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's going on"); Empty
}

If I take out the first case expression, everything works as expected. I’m tempted to think this is a bug (https://issues.scala-lang.org/browse/SI-2337), but does anyone know of a workaround?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:32:40+00:00Added an answer on May 23, 2026 at 6:32 am

    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")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks for the three excellent answers which all identified my problem of using "onclick
Thanks to all that responded to my previous thread. There is still a problem
I'm attempting the example from the excellent How Do I video for MVVM by
Ok, I asked this question and got excellent code example as answer. The code
Thanks to this excellent analysis of the Plot algorithm by Yaroslav Bulatov, I now
I've been working with the excellent jqGrid plugin, and it works great. Recently though,
thanks in advance for this excellent source of help. I've been reading a lot
First of all, many thanks to Craig for the excellent answer below which I
I'm using some modifications to Glenn Berry's excellent DMV queries! However, I would like
Thanks to the answer on this stackoverflow question I was able to get the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.