-
-
Notifications
You must be signed in to change notification settings - Fork 610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
foreach on delegates incorrectly rejected #19256
Labels
Comments
dlang-bugzilla (@CyberShadow) commented on 2017-06-07T13:26:14ZYour example works here. Could you specify the compiler version and compilation flags? |
eyal commented on 2017-06-07T13:40:36Z(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? |
dlang-bugzilla (@CyberShadow) commented on 2017-06-07T13:42:50Z(In reply to Eyal from comment #2)
> Perhaps you didn't pass -unittest?
Yep, my bad |
dlang-bugzilla (@CyberShadow) commented on 2017-06-07T13:44:24ZAdding `ref` to `char a` fixes compilation, but it's still weird that `ref`'s presence is inconsistently needed. |
eyal commented on 2017-06-07T22:04:35Z(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. |
stanislav.blinov commented on 2021-12-08T19:15:52ZThis 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? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Eyal reported this on 2017-06-06T22:43:12Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=17473
CC List
Description
Here is an incorrect rejection of a valid program: struct S { int f(int delegate(char a) dlg) { char c = cast(char)50; return dlg(c); } } unittest { S s; pragma(msg, typeof(&s.f)); // int delegate(int delegate(char a) dlg) foreach(x; &s.f) {} int delegate(int delegate(char a) dlg) g = &s.f; pragma(msg, typeof(g)); // int delegate(int delegate(char a) dlg) foreach(x; g) {} // FAILS }The text was updated successfully, but these errors were encountered: