Thread overview
[Issue 17473] foreach on delegates incorrectly rejected
Jun 07, 2017
Vladimir Panteleev
Jun 07, 2017
Eyal
Jun 07, 2017
Vladimir Panteleev
Jun 07, 2017
Vladimir Panteleev
Jun 07, 2017
ag0aep6g@gmail.com
Jun 07, 2017
Eyal
Dec 08, 2021
Stanislav Blinov
June 07, 2017
https://issues.dlang.org/show_bug.cgi?id=17473

Vladimir Panteleev <thecybershadow@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow@gmail.com

--- Comment #1 from Vladimir Panteleev <thecybershadow@gmail.com> ---
Your example works here. Could you specify the compiler version and compilation flags?

--
June 07, 2017
https://issues.dlang.org/show_bug.cgi?id=17473

--- Comment #2 from Eyal <eyal@weka.io> ---
(In reply to Vladimir Panteleev from comment #1)
> Your example works here. Could you specify the compiler version and compilation flags?

dmd --version
DMD64 D Compiler v2.074.0
Copyright (c) 1999-2017 by Digital Mars written by Walter Bright

dmd -unittest testdlg.d
int delegate(int delegate(char a) dlg)
int delegate(int delegate(char a) dlg)
testdlg.d(15): Error: delegate g (int delegate(char a) dlg) is not callable
using argument types (int delegate(ref char __applyArg0) pure nothrow @nogc
@safe)


Perhaps you didn't pass -unittest?

--
June 07, 2017
https://issues.dlang.org/show_bug.cgi?id=17473

--- Comment #3 from Vladimir Panteleev <thecybershadow@gmail.com> ---
(In reply to Eyal from comment #2)
> Perhaps you didn't pass -unittest?

Yep, my bad

--
June 07, 2017
https://issues.dlang.org/show_bug.cgi?id=17473

--- Comment #4 from Vladimir Panteleev <thecybershadow@gmail.com> ---
Adding `ref` to `char a` fixes compilation, but it's still weird that `ref`'s presence is inconsistently needed.

--
June 07, 2017
https://issues.dlang.org/show_bug.cgi?id=17473

ag0aep6g@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
                 CC|                            |ag0aep6g@gmail.com

--
June 07, 2017
https://issues.dlang.org/show_bug.cgi?id=17473

--- Comment #5 from Eyal <eyal@weka.io> ---
(In reply to Vladimir Panteleev from comment #4)
> Adding `ref` to `char a` fixes compilation, but it's still weird that `ref`'s presence is inconsistently needed.

It also changes the meaning of the program in an undesired way.

--
December 08, 2021
https://issues.dlang.org/show_bug.cgi?id=17473

Stanislav Blinov <stanislav.blinov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |stanislav.blinov@gmail.com

--- Comment #6 from Stanislav Blinov <stanislav.blinov@gmail.com> ---
This probably should be changed to accepts-invalid instead. Foreach is documented as taking delegates with a ref parameter:

https://dlang.org/spec/statement.html#foreach-statement

...therefore that the line `foreach(x; &s.f);` compiles should be an error,
shouldn't it?

--
December 13
https://issues.dlang.org/show_bug.cgi?id=17473

--- Comment #7 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19256

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--