On Mon, 28 Jun 2010 16:07:43 +0200, Philippe Sigaud <[email protected]> wrote:

On Mon, Jun 28, 2010 at 15:40, Rory McGuire <[email protected]> wrote:

void main()
{
   auto fun(string s) { return s;} // this does not compile
}


Hope this isn't a stupid question, but how would you access this function if it did work?
Would it be fun("asdf")?

Yes, that's what I had in mind. Basically, just using it as any other auto inner function.

void main()
{
auto fun(string s) { return s;}
auto s = fun("abc");
auto t = fun("def");
}
 
Is this just shorthand for:
auto fun = function(string s) {return s;};

That'd be about the same, yes. Fact is, I don't really _need_ this, I was just astonished to be bitten by this.
Why can I do

void main()
{
    string foo(string s) { return s;}
}

and not

void main()
{
    auto foo(string s) { return s;}
}

?

***

OK, I tested it some more, and it seems you cannot define auto function inside any other function. So auto function cannot be inner functions. I'm quite astonished I never did that when using D, but OK.

I filed a bug report, at least to update the docs. It's bug #4401.


Philippe




Right! I get what you're saying, didn't realise because it was formatted more how I would format a anon delegate.
You're saying "surely the compiler can infer the return type for a inner function just as much as it can infer the return type of a normal function..

Must be a compiler bug.

-Rory

Reply via email to