digitalmars.D.bugs - [Issue 693] New: 'this' can't be used as an alias parameter for a mixin
- d-bugmail puremagic.com (43/43) Dec 16 2006 http://d.puremagic.com/issues/show_bug.cgi?id=693
- d-bugmail puremagic.com (16/16) Nov 26 2010 http://d.puremagic.com/issues/show_bug.cgi?id=693
- d-bugmail puremagic.com (18/18) Apr 12 2011 http://d.puremagic.com/issues/show_bug.cgi?id=693
- d-bugmail puremagic.com (32/32) Apr 12 2011 http://d.puremagic.com/issues/show_bug.cgi?id=693
- d-bugmail puremagic.com (10/10) May 07 2011 http://d.puremagic.com/issues/show_bug.cgi?id=693
- d-bugmail puremagic.com (12/12) Jul 01 2011 http://d.puremagic.com/issues/show_bug.cgi?id=693
- d-bugmail puremagic.com (12/12) Jan 21 2013 http://d.puremagic.com/issues/show_bug.cgi?id=693
http://d.puremagic.com/issues/show_bug.cgi?id=693 Summary: 'this' can't be used as an alias parameter for a mixin Product: D Version: 0.177 Platform: All OS/Version: All Status: NEW Severity: minor Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: wbaxter gmail.com This may not be a bug for some technical reason unbeknownst to me that the spec mentions (if so downgrade it to enhancement please), but I found it unexpected. You can't use 'this' as an alias paramter to a mixin in a class member function. The workaround is pretty easy, you just assign it to a local dummy variable, and use that instead. import std.stdio : writefln; template printer_mix(alias T) { void print() { writefln(T); } } class Foo { void dump() { // Error: mixin printer_mix!(this) does not match any template declaration mixin printer_mix!(this); // this version ok: //Foo x = this; //mixin printer_mix!(x); print(); } char[] toString() { return "I'm Batman"; } } void main() { Foo f = new Foo(); f.dump(); } --
Dec 16 2006
http://d.puremagic.com/issues/show_bug.cgi?id=693 Andrei Alexandrescu <andrei metalanguage.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED CC| |andrei metalanguage.com AssignedTo|nobody puremagic.com |bugzilla digitalmars.com 13:33:57 PST --- Bug present in 1.065 and 2.050 with different error messages. 1.065: test.d(14): Error: mixin printer_mix!(this) does not match template declaration printer_mix(alias T) 2.050: test.d(14): Error: expression this is not a valid template value argument -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 26 2010
http://d.puremagic.com/issues/show_bug.cgi?id=693 Simen Kjaeraas <simen.kjaras gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |simen.kjaras gmail.com PDT --- This also a problem for non-mixin templates: struct MyCallable { int opCall( int n ) { return n; } auto mapthis( int[] arr ) { return map!this( arr ); } } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 12 2011
http://d.puremagic.com/issues/show_bug.cgi?id=693 PDT --- Thinking about this some more, fixing this bug could lead to safer array indexing for one, through a limited system of dependent types: struct SafeArray( T ) { T[] data; struct Index( alias arr ) { size_t idx; // Add safety checks, overflow handling, etc. } Index!this makeIndex( size_t n ) { typeof( return ) result; result.idx = n; return result; } T opIndex( Index!this idx ) { return data[idx.idx]; } } unittest { SafeArray!int arr; arr.data = [1,2,3,4,5,6,7,8,9,0]; auto idx = arr.makeIndex( 3 ); writeln( arr[idx] ); // Completely safe indexing of array, enforced by type system. } There may be a problem in that compiler considers 'this' a local parameter to a non-global template, which is currently illegal. Not sure how much of a problem this might be in practice. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 12 2011
http://d.puremagic.com/issues/show_bug.cgi?id=693 Kenji Hara <k.hara.pg gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |zan77137 nifty.com *** Issue 4799 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 07 2011
http://d.puremagic.com/issues/show_bug.cgi?id=693 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |RESOLVED Resolution| |FIXED 00:31:09 PDT --- https://github.com/D-Programming-Language/dmd/commit/5a1f396e915e083ce30c5f09f4e1ef1a9e704fda https://github.com/D-Programming-Language/dmd/commit/c9e26681a834beb6b211f41234163707453f4ff1 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 01 2011
http://d.puremagic.com/issues/show_bug.cgi?id=693 Commits pushed to master at https://github.com/D-Programming-Language/d-programming-language.org https://github.com/D-Programming-Language/d-programming-language.org/commit/9e84dccf6286dd7e718f247bf1a623cd50f68553 fix Issue 693 - 'this' can't be used as an alias parameter for a mixin https://github.com/D-Programming-Language/d-programming-language.org/commit/0cf09c6b06c13345024772864f6654002904244c Issue 693 - 'this' can't be used as an alias parameter for a mixin -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 21 2013