google / google/closure-compiler

[request] How to annotate failure or ⊥?

Open
#3,530 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

How can you annotate a function that "fails" / returns the [bottom type](https://en.wikipedia.org/wiki/Bottom_type) ⊥ / "always throws an exception"? For example:

```js
function panic (e) { console.error('panic: ' + e); throw new Error(e) }
```

While its return type is naively void, it's really `⊥`. Code directly following an invocation of `panic(e)` can be assumed to never run. And code following a branch can safely assume that any conditions that would've led to `panic(e)` were false. Knowing this, a compiler can often make extreme optimizations.

If it doesn't exist, could you add a failure annotation?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.