I would hate to stop the implementation of a useful feature, but isn't this against the current spec?
http://dlang.org/expression.html#FunctionLiteral
"If the keywords function or delegate are omitted, it defaults to being a delegate."
Ali
Comment #4 by issues.dlang — 2012-02-27T16:56:33Z
TDPL says that it's inferred.
Comment #5 by github-bugzilla — 2012-02-29T12:19:43Z
Comment #10 by andrej.mitrovich — 2013-02-05T13:08:39Z
What's the state of this? OP sample works, but in Kenji's Comment #1 sample the line which fails is:
Callback cb3 = &Wrap!(f3); // NG
Comment #11 by timon.gehr — 2013-02-05T13:27:23Z
(In reply to comment #10)
> What's the state of this? OP sample works, but in Kenji's Comment #1 sample the
> line which fails is:
>
> Callback cb3 = &Wrap!(f3); // NG
It is to be expected that this fails. If the OP sample works, I assume this is fixed.
Comment #12 by andrej.mitrovich — 2013-02-05T13:28:09Z
(In reply to comment #11)
> (In reply to comment #10)
> > What's the state of this? OP sample works, but in Kenji's Comment #1 sample the
> > line which fails is:
> >
> > Callback cb3 = &Wrap!(f3); // NG
>
> It is to be expected that this fails. If the OP sample works, I assume this is
> fixed.
I guess he also expects this to fail then:
Callback cb3 = &Wrap!((){}); // NG
but it doesn't fail.
Comment #13 by timon.gehr — 2013-02-05T13:32:58Z
(In reply to comment #12)
> (In reply to comment #11)
> > (In reply to comment #10)
> > > What's the state of this? OP sample works, but in Kenji's Comment #1 sample the
> > > line which fails is:
> > >
> > > Callback cb3 = &Wrap!(f3); // NG
> >
> > It is to be expected that this fails. If the OP sample works, I assume this is
> > fixed.
>
> I guess he also expects this to fail then:
>
> Callback cb3 = &Wrap!((){}); // NG
>
> but it doesn't fail.
This should work. What he wanted to show is that (){ } currently behaves like f3, while it should behave like f1 or f2.
Comment #14 by k.hara.pg — 2013-02-05T17:19:33Z
(In reply to comment #10)
> What's the state of this? OP sample works, but in Kenji's Comment #1 sample the
> line which fails is:
>
> Callback cb3 = &Wrap!(f3); // NG
The sample in comment#1 was shown old broken compiler behavior.
> Callback cb1 = &Wrap!(f1); // OK
> Callback cb2 = &Wrap!(f2); // OK
The Wrap function inside Wrap template is declared with extern(C). So it cannot have any hidden context pointer. And, calling f1 or f2 will not need such extra pointer, then Wrap!(f1) and Wrap!(f2) will succeed to compile.
> Callback cb3 = &Wrap!(f3); // NG
f3 is a nested function. So the Wrap function should get a hidden context to main function, but it is impossible. Then the instantiation Wrap!(f3) will fail.
> Callback cb3 = &Wrap!((){}); // NG
This should be compiled. The lambda function (){} has no outer context access, so it should not be treated as nested. But, it had been accidentally done.
As a conclusion, current compiler works as expected. This bug is already fixed.