DIP 1017--Add Bottom Type--Final Review

Paul Backus snarwin at gmail.com
Wed Jan 16 23:43:54 UTC 2019


On Wednesday, 16 January 2019 at 23:32:22 UTC, luckoverthere 
wrote:
> On Wednesday, 16 January 2019 at 23:08:38 UTC, Paul Backus 
> wrote:
>> Here's an example I ran into while working on my 
>> `expectations` library. [1]
>>
>> [...]
>
> As far as the DIP goes, it does not appear to make any mention 
> of it working this way. It does say that the bottom type is 
> implicitly convertible to any type, but being implicitly 
> convertible does not mean that function types are also 
> implicitly convertible. Just as float and int may be implicitly 
> convertible, their functions are not. The only function types 
> that appear to be implicitly convertible are those of class and 
> their derived classes.
>
> This would mean that the bottom type function would need to be 
> ABI compatible with every single function type. I'm not sure if 
> that's possible, but I feel that would need to addressed in the 
> DIP.

`match` is a template function whose return type is inferred from 
the lambdas passed to it (i.e., it returns `auto`).

If an auto-returning function has multiple return statements that 
return values of different types, then the function's return type 
is inferred to be the common type to which all of those different 
types are implicitly convertible. You can see this for yourself 
by compiling the following example:

auto fun(bool b) {
     if (b) return int.init;
     else return double.init;
}

import std.traits;
pragma(msg, ReturnType!fun); // double

It follows that if `match` is called with a lambda that returns 
Tbottom, and a lambda that returns T, its return type will be 
inferred to be T.


More information about the Digitalmars-d mailing list