www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - possible mixin template bug?

reply "growler" <growlercab gmail.com> writes:
This compiles and runs but I think it is a bug.
---
import std.stdio;
mixin template TestMixin(T) {
     int testMixin;
}
struct Test {
     int testMixin;
     mixin TestMixin!Test;
}
void main() {
     Test t;
     t.testMixin = 10;
     writefln("%s", t);
}
---
$ ./hack
Test(10, 0)

I can also change the struct to be:
---
struct Test {
    string testMixin;
    mixin TestMixin!Test;
}
// and the assignment in main() to
t.testMixin = "some string";
---
$ ./hack
Test("some string", 0)

so whether this is a bug or not, I think it is bad. Any thoughts?

G.
Sep 23 2013
next sibling parent Kenji Hara <k.hara.pg gmail.com> writes:
--047d7b873d1abad8f904e70be0f3
Content-Type: text/plain; charset=UTF-8

The symbols that are introduced by mixin template never override/conflict
with the formally defined symbols.
It's a designed behavior.

Kenji Hara


2013/9/23 growler <growlercab gmail.com>

 This compiles and runs but I think it is a bug.
 ---
 import std.stdio;
 mixin template TestMixin(T) {
     int testMixin;
 }
 struct Test {
     int testMixin;
     mixin TestMixin!Test;
 }
 void main() {
     Test t;
     t.testMixin = 10;
     writefln("%s", t);
 }
 ---
 $ ./hack
 Test(10, 0)

 I can also change the struct to be:
 ---
 struct Test {
    string testMixin;
    mixin TestMixin!Test;
 }
 // and the assignment in main() to
 t.testMixin = "some string";
 ---
 $ ./hack
 Test("some string", 0)

 so whether this is a bug or not, I think it is bad. Any thoughts?

 G.

--047d7b873d1abad8f904e70be0f3 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div>The symbols that are introduced by mixin template nev= er override/conflict with the formally defined symbols.</div><div>It&#39;s = a designed behavior.</div><div><br></div><div>Kenji Hara</div></div><div cl= ass=3D"gmail_extra"> <br><br><div class=3D"gmail_quote">2013/9/23 growler <span dir=3D"ltr">&lt;= <a href=3D"mailto:growlercab gmail.com" target=3D"_blank">growlercab gmail.= com</a>&gt;</span><br><blockquote class=3D"gmail_quote" style=3D"margin:0 0= 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> This compiles and runs but I think it is a bug.<br> ---<br> import std.stdio;<br> mixin template TestMixin(T) {<br> =C2=A0 =C2=A0 int testMixin;<br> }<br> struct Test {<br> =C2=A0 =C2=A0 int testMixin;<br> =C2=A0 =C2=A0 mixin TestMixin!Test;<br> }<br> void main() {<br> =C2=A0 =C2=A0 Test t;<br> =C2=A0 =C2=A0 t.testMixin =3D 10;<br> =C2=A0 =C2=A0 writefln(&quot;%s&quot;, t);<br> }<br> ---<br> $ ./hack<br> Test(10, 0)<br> <br> I can also change the struct to be:<br> ---<br> struct Test {<br> =C2=A0 =C2=A0string testMixin;<br> =C2=A0 =C2=A0mixin TestMixin!Test;<br> }<br> // and the assignment in main() to<br> t.testMixin =3D &quot;some string&quot;;<br> ---<br> $ ./hack<br> Test(&quot;some string&quot;, 0)<br> <br> so whether this is a bug or not, I think it is bad. Any thoughts?<span clas= s=3D"HOEnZb"><font color=3D"#888888"><br> <br> G.<br> </font></span></blockquote></div><br></div> --047d7b873d1abad8f904e70be0f3--
Sep 23 2013
prev sibling parent "growler" <growlercab gmail.com> writes:
On Monday, 23 September 2013 at 12:08:37 UTC, Kenji Hara wrote:
 The symbols that are introduced by mixin template never 
 override/conflict
 with the formally defined symbols.
 It's a designed behavior.

 Kenji Hara

Thanks Kenji for the information. I guess I'd better go back and read the docs again...and scurry off back to D.learn :D G.
Sep 23 2013