Struct constructors and opCall

Robert Fraser fraserofthenight at gmail.com
Tue Mar 17 17:19:55 PDT 2009


Lars Kyllingstad wrote:
> I've come across the following strange behaviour in D2. Consider a 
> struct with a constructor, static opCall and non-static opCall:
> 
>     import std.stdio;
> 
>     struct Foo
>     {
>         this(int i)               { writefln("constructor"); }
>         static void opCall(int i) { writefln("static opCall"); }
>         void opCall(int i)        { writefln("instance opCall"); }
>     }
> 
>     void main()
>     {
>         auto foo = Foo(1);
>         Foo(1);
>         foo(1);
>     }
> 
> I expected that either compilation should fail because of ambiguity, or 
> the program should compile and run with the following output:
> 
>     constructor
>     static opCall
>     instance opCall
> 
> Instead, compiled with the newest DMD (2.026), it prints
> 
>     constructor
>     constructor
>     constructor
> 
> This has to be a bug. Is it a known one? I tried searching for "struct 
> constructor opCall" in both Bugzilla and Google, but couldn't find 
> anything.
> 
> -Lars

You can always report it as a bug and if its a duplicate; it'll be 
closed as one.



More information about the Digitalmars-d mailing list