dotnet / dotnet/csharplang

[Proposal]: never/bottom type

Open
#8,604 0 comments 0 reactions 1 assignee Claimed by @333fred View on GitHub
Proposal champion
Dominant language
C#
Stars
12.7k
Forks
1.1k
Avg merge
11h 1m
Merged PRs (30d)
3

Description

# `never`/`bottom` type

* Discussion: https://github.com/dotnet/csharplang/discussions/8603

## Summary
[summary]: #summary

A new type that has no instances and is a subtype of every other type can be introduced, called `never` or `bottom`. It will be the official return type of the `throw` expression and will allow transforming `return`, `break`, `continue` and `goto` into expressions (see https://github.com/dotnet/csharplang/issues/176). This will allow them in all expression contexts where `never` is combined with another type (`&&`, `||`, `??`, `?:`) or discarded (expression statements). Instantiating variables/fields of type `never` should be impossible.

It can either be implemented as a real CLR type (well, as real as `void`) or as a compiler trick (`never`-returning methods are actually `void` with a `NeverReturnsAttribute`).

## Design meetings

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.