Why does Nullable implicitly casts when assigning a variable but not when returning from a function?

Lettever real at email.com
Wed Apr 10 21:43:07 UTC 2024


On Wednesday, 10 April 2024 at 21:38:22 UTC, Andy Valencia wrote:
> On Wednesday, 10 April 2024 at 20:41:56 UTC, Lettever wrote:
>> ```
>> import std;
>>
>> Nullable!int func() => 3;
>> void main() {
>>     Nullable!int a = 3;
>>     //works fine
>>     Nullable!int b = func();
>>     //does not compile
>> }
>
> Why make func() Nullable?  It just wants to give you an int, 
> right?  Making it a function returning an int fixes this.
>
> Andy

Its an example


More information about the Digitalmars-d-learn mailing list