lampepfl / dotty-feature-requests

Historical feature requests. Please create new feature requests at https://github.com/lampepfl/dotty/discussions/new?category=feature-requests
31 stars 2 forks source link

Add !!! to throw ShouldNeverHappenException #78

Open oscar-broman opened 4 years ago

oscar-broman commented 4 years ago

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 => !!!
}
LPTK commented 4 years ago

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

som-snytt commented 4 years ago

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 commented 4 years ago

It should throw InconceivableException().

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