Thread overview | |||||
---|---|---|---|---|---|
|
May 02, 2016 Lambda return type bug? | ||||
---|---|---|---|---|
| ||||
Hi, I think this code should work, but the compiler does not agree. Am I missing something? void main() { alias funType = void function(int x); funType fun = (x) => { assert(x); }; // cannot return non-void from void function fun(0); } From the language reference I understand that assert shoud return void, so I can't see how this code is wrong. |
May 02, 2016 Re: Lambda return type bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lodovico Giaretta | On Monday, 2 May 2016 at 08:09:47 UTC, Lodovico Giaretta wrote:
> Hi,
>
> I think this code should work, but the compiler does not agree.
> Am I missing something?
>
> void main()
> {
> alias funType = void function(int x);
> funType fun = (x) => { assert(x); }; // cannot return non-void from void function
> fun(0);
> }
>
> From the language reference I understand that assert shoud return void, so I can't see how this code is wrong.
Wrong syntax!
You mean (x) { assert(x); }
or
(x) => assert(x)
|
May 02, 2016 Re: Lambda return type bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrea Fontana | On Monday, 2 May 2016 at 08:18:45 UTC, Andrea Fontana wrote:
> On Monday, 2 May 2016 at 08:09:47 UTC, Lodovico Giaretta wrote:
>> Hi,
>>
>> I think this code should work, but the compiler does not agree.
>> Am I missing something?
>>
>> void main()
>> {
>> alias funType = void function(int x);
>> funType fun = (x) => { assert(x); }; // cannot return non-void from void function
>> fun(0);
>> }
>>
>> From the language reference I understand that assert shoud return void, so I can't see how this code is wrong.
>
> Wrong syntax!
> You mean (x) { assert(x); }
>
> or
>
> (x) => assert(x)
Lol... Noob error...
Got confused by the two different ways of writing functions...
Thank you very much (and sorry for wasting some of your time...)
|
Copyright © 1999-2021 by the D Language Foundation