www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - DMD 0.95: mixins don't allow overriding by base symbols in a type

reply Burton Radons <burton-radons shaw.ca> writes:
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
    }
Jul 18 2004
parent reply Derek Parnell <derek psych.ward> writes:
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
Jul 19 2004
next sibling parent reply "Ivan Senji" <ivan.senji public.srce.hr> writes:
"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

Jul 19 2004
next sibling parent Derek <derek psyc.ward> writes:
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
Jul 19 2004
prev sibling parent Andrew <Andrew_member pathlink.com> writes:
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); }
Jul 19 2004
prev sibling next sibling parent reply Andrew <Andrew_member pathlink.com> writes:
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

Jul 19 2004
parent "Ivan Senji" <ivan.senji public.srce.hr> writes:
"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


Jul 19 2004
prev sibling parent reply Burton Radons <burton-radons shaw.ca> writes:
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.
Jul 19 2004
parent "Walter" <newshound digitalmars.com> writes:
"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


 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.
Jul 30 2004