Comment #0 by lutger.blijdestijn — 2007-07-02T19:05:32Z
When a struct has opCall through an alias, it is not recognized if the aliased symbol is a delegate (not as in a member function). Whether this construct is legal or not, the current behaviour is inconsistent. The following compiles without error but does not do what one expects.
This applies to dmd 1.014-dmd 1.018 and probably the 2.x branch too.
struct A
{
int delegate() foo;
alias foo opCall; // not seen, see below
}
struct B
{
int foo() { return 0; }
alias foo opCall; // ok
}
void main()
{
A a;
B b;
auto resultA = a();
pragma(msg, typeof(resultA).stringof); // prints 'A', struct initializer
auto resultB = b();
pragma(msg, typeof(resultB).stringof); // prints 'int', recognizes opCall
}
Comment #1 by thomas-dloop — 2007-07-23T14:55:37Z
The same behaviour is caused by:
# struct A {
# int opCall;
# }
As far as I can see the code behaves as documented - opCall expects a function
not a delegate or function pointer - however issuing at least a warning if -w
is used would be sensible. Adding delegate/function pointer support for op*
member functions might be interesting nevertheless.
Comment #2 by verylonglogin.reg — 2012-08-09T02:30:40Z
By the way, latest dmd v2.060 correctly (as documented) complains:
---
Error: struct A does not overload ()
---
Comment #3 by razvan.nitu1305 — 2019-07-12T13:58:49Z
(In reply to Denis Shelomovskii from comment #2)
> By the way, latest dmd v2.060 correctly (as documented) complains:
> ---
> Error: struct A does not overload ()
> ---
This is the correct behavior. Closing as WONTFIX.