www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - mixin virtual function bug

reply "John C" <johnch_atms hotmail.com> writes:
In the spec on mixins (http://www.digitalmars.com/d/mixin.html) it states 
"Mixins can add virtual functions to a class". The following shows this to 
be true:

    template Virtuals {
        void test() { printf("Virtuals.test");
    }

    class Target {
        mixin Virtuals;
        void test() { printf("Target.test");
    }

    Target t = new Target;
    t.test(); // prints "Target.test"

However, it the virtual mechanism breaks down when using interfaces:

    interface ITarget {
        void test();
    }

    class Target : ITarget {
        mixin Virtuals;
        void test() { printf("Target.test");
    }

    ITarget t = new Target;
    t.test(); // prints "Virtuals.test"

I would expect the above line to print "Target.test" as in the first 
examples.

John. 
Jan 24 2006
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John C schrieb am 2006-01-24:
 In the spec on mixins (http://www.digitalmars.com/d/mixin.html) it states 
 "Mixins can add virtual functions to a class". The following shows this to 
 be true:

     template Virtuals {
         void test() { printf("Virtuals.test");
     }

     class Target {
         mixin Virtuals;
         void test() { printf("Target.test");
     }

     Target t = new Target;
     t.test(); // prints "Target.test"

 However, it the virtual mechanism breaks down when using interfaces:

     interface ITarget {
         void test();
     }

     class Target : ITarget {
         mixin Virtuals;
         void test() { printf("Target.test");
     }

     ITarget t = new Target;
     t.test(); // prints "Virtuals.test"

 I would expect the above line to print "Target.test" as in the first 
 examples.

 John. 
Added to DStress as http://dstress.kuehne.cn/run/m/mixin_15_A.d http://dstress.kuehne.cn/run/m/mixin_15_B.d http://dstress.kuehne.cn/run/m/mixin_15_C.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFD1nLW3w+/yD4P9tIRAjBrAJwN9f6krZ3upAg6mSZYXIRmDXBIfQCgrLM9 JTfgbVu+OrjdEE29YzeWoNE= =NbTz -----END PGP SIGNATURE-----
Jan 25 2006