template mixin bug?
Regan Heath
regan at netmail.co.nz
Tue Nov 13 07:50:34 PST 2007
Simen Haugen wrote:
> I have a mixin like this:
> template M() {
> int i() {
> return _i;
> }
>
> private:
> int _i;
> }
>
> But if I try to add a setter function to my class that uses the mixin, the
> compiler gets confused (seems like its hiding the mixed in function):
> class C {
> mixin Mixin;
> void i(int a) {
> _i = a;
> }
> }
>
> void main() {
> C c = new C;
> c.i = 12;
> assert(c.i == 12);
> }
>
> Now it fails to compile if I try to use the get method from the mixin. If I
> don't use the method, it compiles.
>
> t.d(29): function test.C.i (int) does not match parameter types ()
> t.d(29): Error: expected 1 arguments, not 0
> t.d(29): Error: void has no value
> t.d(29): Error: incompatible types for (((c.i)()) == (12)): 'void' and 'int'
>
> Is there a reason I cannot do this, or is it a compiler bug? I'm using dmd
> 1.023.
>
>
Here is a workaround, change the mixin and add an alias:
mixin M b;
alias b.i i;
As for whether it's a bug <shrug>.
Regan
More information about the Digitalmars-d
mailing list