constructor instead of opCall for an instance of a template alias

Ali Çehreli acehreli at yahoo.com
Sun Nov 25 08:01:39 PST 2012


On 11/25/2012 07:27 AM, comco wrote:
 >
 >> A!B(...) defines a struct A with B typed in as Method, so call to
 >> method(s); is the same as B(string)
 > Why is that? Here method is an instance of the type Method, not the type
 > Method itself,

That could be case but you original code did use a type name for Method:

     A!B(B(0));

This would be using an instance:

     B instance;
     A!instance(B(0));

It would not compile because you would be using an instance as a type 
name in the constructor signature:

     this(Method method) {    // <-- ERROR: Method is an instance
         // ...
     }

 > so by saying `method(s)` we can't mean a constructor.
 > Something very strange happens...

The situation with constructors and opCall() are still confused. There 
are a number of bugs open but not exactly this one.

 > I have a simpler example now:

Even simpler:

struct A
{
     int i;

     void opCall(int i) {
     }
}

void main() {
     auto a = A(42);
}

Error: variable deneme.main.a type void is inferred from initializer 
opCall(42), and variables cannot be of type void
Error: expression opCall(42) is void and has no value

The bug is that a non-static opCall() is chosen instead of the default 
constructor. As you say, non-static opCall() overloads should not 
interfere with construction.

Could you please create a bug report:

   http://d.puremagic.com/issues/

Ali



More information about the Digitalmars-d-learn mailing list