digitalmars.D.bugs - Mixin bug
- Roel Mathys (12/12) May 17 2004 template Mix1() { this(int x) { printf("mix1\n"); }}
- Derek Parnell (56/72) May 18 2004 Confirmed, sort of...
template Mix1() { this(int x) { printf("mix1\n"); }} class Bar { int myx; //~ mixin Mix1; ==> wouldn't compile this() { myx = 15; } mixin Mix1; ==> placing it here compiles } int main() { Bar bar = new Bar(); return 0; }
May 17 2004
On Tue, 18 May 2004 08:29:27 +0200, Roel Mathys wrote:template Mix1() { this(int x) { printf("mix1\n"); }} class Bar { int myx; //~ mixin Mix1; ==> wouldn't compile this() { myx = 15; } mixin Mix1; ==> placing it here compiles } int main() { Bar bar = new Bar(); return 0; }Confirmed, sort of... With this code ... //---------------------- template Mix1(alias y) { this(int x) { y = x; printf("mix1\n"); } } class Bar { int myx; this() { myx = 15; } //mixin Mix1!(myx); // ==> placing it here compiles this(int x) { myx = x; printf("mix2\n");} } int main() { Bar bar1 = new Bar(); Bar bar2 = new Bar(4); printf("1 %d, 2 %d\n", bar1.myx, bar2.myx); return 0; } //---------------------- I get ... c:\temp>dmd mix C:\DPARNELL\DMD\BIN\..\..\dm\bin\link.exe mix,,,user32+kernel32/noi; c:\temp>mix mix2 1 15, 2 4 ... but when I replace the hard coded ctor(int) with the mixin ... //---------------------- template Mix1(alias y) { this(int x) { y = x; printf("mix1\n"); } } class Bar { int myx; this() { myx = 15; } mixin Mix1!(myx); // ==> placing it here compiles //this(int x) { myx = x; printf("mix2\n");} } int main() { Bar bar1 = new Bar(); Bar bar2 = new Bar(4); printf("1 %d, 2 %d\n", bar1.myx, bar2.myx); return 0; } //---------------------- ... I get this ... c:\temp>dmd mix mix.d(17): constructor this () does not match argument types (int) So it appears that any ctor brought in by a mixin is ignored if any ctor already exists for the class. -- Derek 18/May/04 6:28:40 PM
May 18 2004