Feedback Thread: DIP 1034--Add a Bottom Type (reboot)--Final Review
Dennis
dkorpel at gmail.com
Tue Sep 22 15:08:04 UTC 2020
On Tuesday, 22 September 2020 at 14:16:19 UTC, Steven
Schveighoffer wrote:
> ```
> int x;
> int bar();
> auto foo() {
> cast(noreturn) (x = bar()); // same as {x = bar();
> assert(0);}
> }
> ```
>
> This is odd, and I'm not understanding the reason for the cast
> if you aren't assigning.
This code has no reason, it's just an example of the rewrite that
happens with `cast(noreturn)`. It could actually be useful in
generic code, or when you are using a function that is noreturn
but does not have the correct return type.
```
// someone else's code
void panic(string msg);
// your code:
auto f = () => cast(noreturn) panic("error");
```
> Also, earlier you say that you can declare a noreturn variable,
> but as long as you don't use it, you don't generate the assert
> 0. Is this example a contradiction of that?
I don't think so, the example does not declare a local variable.
I could rewrite it to this:
```
import std;
int x;
int bar();
auto foo() {
noreturn y; // no assert here yet
writeln("this will get printed");
y = cast(noreturn) (x = bar());
// here it results in assert(0)
}
```
The reason for this is argued by Johannes Loher here:
https://forum.dlang.org/post/r8v8tt$14fk$1@digitalmars.com
> ```
> /* 6 */ !(is(T == function)) || is(noreturn* : T)
> /* 7 */ !(is(T == delegate)) || is(noreturn* : T)
> ```
>
> What are these trying to say? I think these rules need some
> clarification or rewriting
In formal logic, "(not p) or q" is equivalent to "if p then q",
so it means "if T is a function/delegate, noreturn* implicitly
converts to it". The DIP follows the rules up with a short
explanation:
> 5, 6 and 7 mean that null (which is of type noreturn*) may
> still be assigned to a function pointer or array.
The point is that these things should still be allowed when
`typeof(null)` becomes equivalent to `noreturn*`:
```
int[] a = null;
void function() f = null;
void delegate() d = null;
Object o = null;
```
(I just realized I have no rule for `T == class`. I sometimes
forget classes exist in D :p)
I'll try to make it clearer.
More information about the Digitalmars-d
mailing list