auto ref deduction and common type deduction inconsistency

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Wed Aug 20 08:33:47 PDT 2014


On 08/20/2014 05:24 PM, "Marc =?UTF-8?B?U2Now7x0eiI=?= 
<schuetzm at gmx.net>" wrote:
> On Wednesday, 20 August 2014 at 15:08:52 UTC, Peter Alexander wrote:
>> On Wednesday, 20 August 2014 at 14:52:59 UTC, ketmar via Digitalmars-d
>> wrote:
>>> On Wed, 20 Aug 2014 14:44:40 +0000
>>> Peter Alexander via Digitalmars-d <digitalmars-d at puremagic.com> wrote:
>>>
>>>> Well, the return type is already the common type of all return paths
>>> no, it's not. the return type will be taken from the first return
>>> statement in code.
>>
>> auto foo() {
>>   if (1) return 1;
>>   return 2.0;
>> }
>>
>> This returns double. Try for yourself.
>
> Then either the compiler or the documentation is wrong :-(
> "If there are multiple ReturnStatements, the types of them must match
> exactly."
> http://dlang.org/function#auto-functions

https://issues.dlang.org/show_bug.cgi?id=8307


More information about the Digitalmars-d mailing list