Regarding Issue 9423
Maxim Fomin
maxim at maxim-fomin.ru
Wed Jan 30 04:11:17 PST 2013
On Wednesday, 30 January 2013 at 11:10:17 UTC, bearophile wrote:
> Currently you are allowed to write a lambda literal as in line
> 3, but you can't omit "ref" as in line 4:
>
>
> void foo(int delegate(ref int[1]) spam) {}
> void main() {
> foo((ref x) => 0); // line3, OK
> foo(x => 0); // line4, Error
> }
>
>
> Do you think "ref" annotation should be required at the call
> site?
Ref isn't at a call site, it is a function declaration and not
passing lambda by ref.
> This is the Bugzilla thread. Hara has already implemented the
> "ref" inference, but he's not sure if it's a good idea:
>
> http://d.puremagic.com/issues/show_bug.cgi?id=9423
>
> Bye,
> bearophile
int delegate(ref int[1] spam) and
int delegate(int[1] spam) are different.
True, the proposal makes code writing convenient, but it can lead
to troubles when foo has overload with non-ref parameter
delegate. This also may probably lead to problems when passed by
delegate function modifies its argument but it is unexpected by
user because function was not annotated with ref. Moreover, this
is a special case in a language.
More information about the Digitalmars-d
mailing list