dotty-feature-requests icon indicating copy to clipboard operation
dotty-feature-requests copied to clipboard

Add !!! to throw ShouldNeverHappenException

Open oscar-broman opened this issue 5 years ago • 3 comments

Not only would !!! be a great companion to ??? but there are also many scenarios where no words are needed to describe that something should not happen.

For example:

acceptThisFeatureRequest match {
  case true => ???
  case false => !!!
}

oscar-broman avatar Nov 07 '19 18:11 oscar-broman

I like this, but it's a standard library request, so maybe a PR on https://github.com/scala/scala should be made.

LPTK avatar Nov 07 '19 18:11 LPTK

A supplemental idea is

@compileTimeOnly
type !!! = Nothing
@compileTimeOnly
type ??? = Any

or similar. That is for transient coding that is safer than def f = ???. It would also serve as a placeholder in didactic presentations.

When def f: !!! = ??? is my last error, I can start to fill in the type. I tried ??? in scala 2 but it didn't build right away, so I haven't played with it yet. But Rust has empty type ! which is suggestive.

The scala 2 folks always say PR on Dotty first and then we can talk.

som-snytt avatar Jun 21 '20 22:06 som-snytt

It should throw InconceivableException().

https://www.reactiongifs.us/wp-content/uploads/2013/10/inconceivable_princess_bride.gif

som-snytt avatar Sep 25 '20 04:09 som-snytt