# Exhaustive case

**URL:** https://forum.crystal-lang.org/t/exhaustive-case/1844
**Category:** Offtopic
**Created:** [March 19, 2020, 5:31pm UTC](https://forum.crystal-lang.org/t/exhaustive-case/1844 "2020-03-19T17:31:39Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)
#### Post date: [March 19, 2020, 5:31pm UTC](https://forum.crystal-lang.org/t/exhaustive-case/1844/1 "2020-03-19T17:31:39Z")

</div>

Is there some way we can make `case` be exhaustive, and force an `else` in case the compiler can’t prove that?

Ref: [https://github.com/crystal-lang/crystal/issues/8001](https://github.com/crystal-lang/crystal/issues/8001)

This is the only thing that really bothers me about Crystal. Having to write `else raise "Bug: can't happen"` is really, really annoying and makes the language look unprofessional.

I know Crystal has several bugs, many related to generics, but these are bugs. They will be fixed, most probably without making a big change in the language.

However, `case` not being exhaustive is not a bug. It doesn’t need to be fixed. It needs to change.

We need to make the language better and more type safe. Requiring hash lookups to match key types is one way to make that happen. Making `case` be exhaustive, like in many other languages, is another way to make that happen.

I already sent a PR with that? Could we move forward with that? What’s the fear?

If I’m in charge of that, there’s no fear about losing time on it because I will be working on it and I’m sure @straight-shoota , @RX14 and other non-Manas people will be able to review it and move it forward.

Thoughts?

---

<div class="post-metadata">

### Author: ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)
#### Post date: [March 19, 2020, 6:44pm UTC](https://forum.crystal-lang.org/t/exhaustive-case/1844/2 "2020-03-19T18:44:45Z")

</div>

Yeah, I really don’t understand why we didn’t already merge [#8424](https://github.com/crystal-lang/crystal/pull/8424). There was a objection late in the process, but the discussion was not picked up again. I’d be fine with merging that PR as is.

---

<div class="post-metadata">

### Author: ![rogerdpack](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/rogerdpack/32/117_2.png) [@rogerdpack](https://forum.crystal-lang.org/u/rogerdpack)
#### Post date: [March 23, 2020, 4:35am UTC](https://forum.crystal-lang.org/t/exhaustive-case/1844/3 "2020-03-23T04:35:55Z")

</div>

Yeah case statements have been one of the few places where I’ve thought “what?” with crystal…

other examples (though they deal with Enum’s, somewhat related?)

> [@Are there plans for exhaustiveness checks on case with enums?](https://forum.crystal-lang.org/t/are-there-plans-for-exhaustiveness-checks-on-case-with-enums/1512):
>
> Given the following code: enum BasicColor Red, Green, Blue end def max\_out(color : BasicColor) : String case color when BasicColor::Red then "#ff0000" when BasicColor::Green then "#00ff00" when BasicColor::Blue then "#0000ff" end end puts max\_out(BasicColor::Red) Currently, you get this error: Error: method must return String but it is returning (String | Nil) This of course makes no sense, because you annotated the method param as exactly BasicColor (not Ba…

[https://groups.google.com/d/msg/crystal-lang/YJbUG1lQP3Q/A2sJzUQACgAJ](https://groups.google.com/d/msg/crystal-lang/YJbUG1lQP3Q/A2sJzUQACgAJ)
