Unexpectedly nice case of auto return type

Basile B. b2.temp at gmx.com
Tue Dec 3 09:48:39 UTC 2019


On Tuesday, 3 December 2019 at 09:44:20 UTC, Basile B. wrote:
> On Tuesday, 3 December 2019 at 08:47:45 UTC, Andrea Fontana 
> wrote:
>> On Tuesday, 3 December 2019 at 07:24:31 UTC, Basile B. wrote:
>>>
>>>     A testA()
>>>     {
>>>         return alwaysReturnNull(); // Tnull can be implictly 
>>> converted to A
>>>     }
>>>
>>> still nice tho.
>>
>> Why not [1]?
>>
>> [1] typeof(null) alwaysReturnNull() { ... }
>>
>> Andrea
>
> Yeah nice, that works instead of auto.
>
> That reminds me of the discussion about TBottom.

You see what surprises me here is that we cannot express the 
special type that is `TypeNull` and that can only have one value 
(`null`) so instead we have to use `auto` or `typeof(null)`.

Making this type public would make the logic more clear: when 
`null` is used it's not a value but rather a value of a type that 
is convertible to all pointers or reference types.


More information about the Digitalmars-d-learn mailing list