Feedback Thread: DIP 1034--Add a Bottom Type (reboot)--Community Review Round 1
Meta
jared771 at gmail.com
Wed May 6 17:08:31 UTC 2020
Copying this over from the discussion thread:
noreturn x0; // compile error, must have bottom value
noreturn[1] x4; // compile error, init value is [assert(0)]
struct S {int x; noreturn y;} // definition is fine
S x5; // compile error, must have bottom value
enum E : noreturn {x = assert(0), y = assert(0)}
E e; // compile error, must have bottom value
The problem is that these require special cases in generic code.
If these common cases cause compile errors, then every template
will either have to have a `if (!is(T == noreturn))`, or allow
itself to fail (possibly deep inside a stack of instantiated
templates).
std.algorithm.group, for example, returns a Group struct, defined
as follows:
struct Group(alias pred, R)
if (isInputRange!R)
{
import std.typecons : Rebindable, tuple, Tuple;
private alias E = ElementType!R;
static if ((is(E == class) || is(E == interface)) &&
(is(E == const) || is(E == immutable)))
{
private alias MutableE = Rebindable!E;
}
else static if (is(E : Unqual!E))
{
private alias MutableE = Unqual!E;
}
else
{
private alias MutableE = E;
}
private R _input;
private Tuple!(MutableE, uint) _current;
...
}
But if R is noreturn[], then this becomes:
struct Group(alias pred, R)
if (isInputRange!R)
{
private noreturn[] _input;
private Tuple!(noreturn, uint) _current;
}
And because Tuple is itself a struct, and Tuple!(noreturn, uint)
has a field of type noreturn, the following code will fail to
compile:
[].group()
With a confusing error message inside Tuple.
I think these rules should at least be reconsidered or relaxed,
if not removed.
More information about the Digitalmars-d
mailing list