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 8200667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:31:46+00:00 2026-06-07T06:31:46+00:00

I caused a bug in my code that was tougher to find that I

  • 0

I caused a bug in my code that was tougher to find that I would have liked, and something that I’d ideally like to avoid in the future. I expected the Scala compiler would have warned me about my error (unless I’m missing something).

I’ve reduced it to the trivial case:

Vector.maybeGetVector match {
  case v:Vector => true
  case _ => false
}

case class Vector(x:Int, y:Int)

object Vector {
  def maybeGetVector : Option[Vector] = Some(new Vector(1,2))
}

The only reason I used wildcard instead of None for the fall through is that I only want to match on a subtype of the returned Option.

I was expecting a compiler warning, as it’s easy to reason that the first case statement contains unreachable code. Option[Vector] can’t be a subtype of Vector.

The strange part is that if I add the following case statement:

 case i:Int => false

It raises an error and tells me that Option[Vector] is required.

Is there a way to protect against programmer error in this way, outside of naming conventions. The only things that can ever match against an Option are Some/None/null. I feel I’m missing something obvious.

  • 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-06-07T06:31:47+00:00Added an answer on June 7, 2026 at 6:31 am

    If you define your Vector class with a final modifier, you’ll get the “pattern type is incompatible with expected type” error you’re expecting.

    To me that says that Scala thinks your Option[Vector] might somehow be an instance of a subtype of Vector. (This seems impossible to me, but I think that’s the reasoning at work.) Making Vector final precludes that seemingly remote possibility.

    So, if the first case statement should be unreachable, it’s not because, as you said, Vector can’t be a subtype of Option[Vector]; but rather because an Option[Vector] can’t be an instance of a subtype of Vector. Maybe that’s what you meant 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very strange bug, which I believe is caused by some code
I have the following code that shows either a bug or a misunderstanding on
I've just fixed a very subtle bug in our code, caused by slicing of
I have developed an AJAX based game where there is a bug caused (very
Edit : The bug that caused this problem has been fixed. The @version tag
I have an odd bug in my program, it appears to me that malloc()
I must be doing something stupid here, because I have some very similar code
I had a bug that caused an integer overflow, resulting in wrong (negative) timestamps
We ran into a bug in our product caused by the fact that for
I saw on code.google.com that there is a bug in method getLocationUpdate() when we

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.