Thread overview
DMD 0.95: mixins don't allow overriding by base symbols in a type
Jul 19, 2004
Burton Radons
Jul 19, 2004
Derek Parnell
Jul 19, 2004
Ivan Senji
Jul 19, 2004
Derek
Jul 19, 2004
Andrew
Jul 19, 2004
Andrew
Jul 19, 2004
Ivan Senji
Jul 19, 2004
Burton Radons
Jul 30, 2004
Walter
July 19, 2004
This code fails compilation with the error code:

   foo.d(20): cannot implicitly convert char[5] to int

The "x" symbol in the template should not be mixed in because it already exists in the scope.  This is the code:

   template t ()
   {
      int x;
   }

   class a
   {
      char [] x;
   }

   class b : a
   {
      mixin t;
   }

   void main ()
   {
      b n;

      n.x = "hello"; // error: cannot implicitly convert char[5] to int
   }
July 19, 2004
On Sun, 18 Jul 2004 23:46:24 -0700, Burton Radons wrote:

>     template t ()
>     {
>        int x;
>     }
> 
>     class a
>     {
>        char [] x;
>     }
> 
>     class b : a
>     {
>        mixin t;
>     }
> 
>     void main ()
>     {
>        b n;
> 
>        n.x = "hello"; // error: cannot implicitly convert char[5] to int
>     }

This is not a mixin bug. It's not really a bug either, I think.

    n.a.x = "hello"; // Works fine.

If you don't use a mixin and just code the "int x;" explicitly, you still get the same message.

I tried using n.t.x = 1; but that threw out a different (and strange)
message ... "test.d(24): no property 't' for type 'b'".

-- 
Derek
Melbourne, Australia
19/Jul/04 5:00:32 PM
July 19, 2004
"Derek Parnell" <derek@psych.ward> wrote in message news:cdfsnj$5hv$1@digitaldaemon.com...
> On Sun, 18 Jul 2004 23:46:24 -0700, Burton Radons wrote:
>
> >     template t ()
> >     {
> >        int x;
> >     }
> >
> >     class a
> >     {
> >        char [] x;
> >     }
> >
> >     class b : a
> >     {
> >        mixin t;
> >     }
> >
> >     void main ()
> >     {
> >        b n;
> >
> >        n.x = "hello"; // error: cannot implicitly convert char[5] to int
> >     }
>
> This is not a mixin bug. It's not really a bug either, I think.
>
>     n.a.x = "hello"; // Works fine.
>
> If you don't use a mixin and just code the "int x;" explicitly, you still get the same message.
>
> I tried using n.t.x = 1; but that threw out a different (and strange)
> message ... "test.d(24): no property 't' for type 'b'".

Not a strange message. You should give a mixin a name to do that: Like

mixin t T;
...
n.T.x = 1;

> --
> Derek
> Melbourne, Australia
> 19/Jul/04 5:00:32 PM


July 19, 2004
On Mon, 19 Jul 2004 11:32:23 +0200, Ivan Senji wrote:

> "Derek Parnell" <derek@psych.ward> wrote in message news:cdfsnj$5hv$1@digitaldaemon.com...
>> On Sun, 18 Jul 2004 23:46:24 -0700, Burton Radons wrote:
>>
>>>     template t ()
>>>     {
>>>        int x;
>>>     }
>>>
>>>     class a
>>>     {
>>>        char [] x;
>>>     }
>>>
>>>     class b : a
>>>     {
>>>        mixin t;
>>>     }
>>>
>>>     void main ()
>>>     {
>>>        b n;
>>>
>>>        n.x = "hello"; // error: cannot implicitly convert char[5] to int
>>>     }
>>
>> This is not a mixin bug. It's not really a bug either, I think.
>>
>>     n.a.x = "hello"; // Works fine.
>>
>> If you don't use a mixin and just code the "int x;" explicitly, you still get the same message.
>>
>> I tried using n.t.x = 1; but that threw out a different (and strange)
>> message ... "test.d(24): no property 't' for type 'b'".
> 
> Not a strange message. You should give a mixin a name to do that: Like
> 
> mixin t T;
> ...
> n.T.x = 1;
> 
>> --
>> Derek
>> Melbourne, Australia
>> 19/Jul/04 5:00:32 PM

Ahhh...of course! Thanks, Ivan.
-- 
Derek
Melbourne, Australia
July 19, 2004
>This is not a mixin bug. It's not really a bug either, I think.
>
>    n.a.x = "hello"; // Works fine.
>
>If you don't use a mixin and just code the "int x;" explicitly, you still get the same message.
>
>I tried using n.t.x = 1; but that threw out a different (and strange)
>message ... "test.d(24): no property 't' for type 'b'".

When Mixed_in, the contents of a template becomes local to the class, thus granting access to a "local" int x.

Try:

void main ()
{
b n = new b; //Otherwise you get a runtime Access Violation error
n.a.x = "hello";
n.x = 1;
}

>-- 
>Derek
>Melbourne, Australia
>19/Jul/04 5:00:32 PM


July 19, 2004
In article <cdg4fa$80i$1@digitaldaemon.com>, Ivan Senji says...
>
>"Derek Parnell" <derek@psych.ward> wrote in message
>
>> This is not a mixin bug. It's not really a bug either, I think.
>>
>>     n.a.x = "hello"; // Works fine.
>>
>> If you don't use a mixin and just code the "int x;" explicitly, you still get the same message.
>>
>> I tried using n.t.x = 1; but that threw out a different (and strange)
>> message ... "test.d(24): no property 't' for type 'b'".
>
>Not a strange message. You should give a mixin a name to do that: Like
>
>mixin t T;
>...
>n.T.x = 1;

Absolutely unnecessary: unless you need to have multiple ways of referring to the same thing (aka alias). With your example above I can do:

void main ()
{
b n = new b; //Otherwise you get a runtime Access Violation error
n.a.x = "hello";
n.x = 777;
printf("%d",n.T.x);
}


July 19, 2004
Derek Parnell wrote:

> This is not a mixin bug. It's not really a bug either, I think.
> 
>     n.a.x = "hello"; // Works fine. 
> 
> If you don't use a mixin and just code the "int x;" explicitly, you still
> get the same message.

"If the name of a declaration in a mixin is the same as a declaration in the surrounding scope, the surrounding declaration overrides the mixin one."  If the scope is limited to being the immediate scope, and not include any nesting scope or dependent scope, fine.  But that's not how the standard is written now.
July 19, 2004
"Andrew" <Andrew_member@pathlink.com> wrote in message news:cdh15p$jnt$1@digitaldaemon.com...
> >This is not a mixin bug. It's not really a bug either, I think.
> >
> >    n.a.x = "hello"; // Works fine.
> >
> >If you don't use a mixin and just code the "int x;" explicitly, you still get the same message.
> >
> >I tried using n.t.x = 1; but that threw out a different (and strange)
> >message ... "test.d(24): no property 't' for type 'b'".
>
> When Mixed_in, the contents of a template becomes local to the class, thus granting access to a "local" int x.
>
> Try:
>
> void main ()
> {
> b n = new b; //Otherwise you get a runtime Access Violation error
> n.a.x = "hello";

I don't understand why this works? Isn't class name only used to acces static members? Or can it be used to acces super class members too?

> n.x = 1;
> }
>
> >--
> >Derek
> >Melbourne, Australia
> >19/Jul/04 5:00:32 PM
>
>


July 30, 2004
"Burton Radons" <burton-radons@shaw.ca> wrote in message news:cdh4i5$l2h$1@digitaldaemon.com...
> Derek Parnell wrote:
>
> > This is not a mixin bug. It's not really a bug either, I think.
> >
> >     n.a.x = "hello"; // Works fine.
> >
> > If you don't use a mixin and just code the "int x;" explicitly, you
still
> > get the same message.
>
> "If the name of a declaration in a mixin is the same as a declaration in the surrounding scope, the surrounding declaration overrides the mixin one."  If the scope is limited to being the immediate scope, and not include any nesting scope or dependent scope, fine.  But that's not how the standard is written now.

Base class members are in a different scope. But I agree the wording could be better.