www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Mixins creating nested functions in class methods

reply David Friedman <d3rdclsmail_a_ _t_earthlink_d_._t_net> writes:
The 'class NotOk' example fails to compile with the error message:

"need 'this' to access member write"

------------------
class Ok {
     void write(int v) { }

     template rwop(alias F) {
	void op() { write(F(42)); }
     }

     ubyte asl(ubyte b) { return b << 1; }

     mixin rwop!(asl) rwAsl;

     void run() {
	rwAsl.op();
     }
}
---------------------
class NotOk {
     void write(int v) { }

     template rwop(alias F) {
	void op() { write(F(42)); }
     }

     ubyte asl(ubyte b) { return b << 1; }

     void run() {
	// this works...
	void rwAslOp() { write(asl(42)); }
	rwAslOp();

	// ... but this does not
	mixin rwop!(asl) rwAsl;
	rwAsl.op();
     }
}
--------------------


David
May 03 2005
parent Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David Friedman schrieb am Tue, 03 May 2005 20:39:00 -0400:
 The 'class NotOk' example fails to compile with the error message:

 "need 'this' to access member write"

 ------------------
 class Ok {
      void write(int v) { }

      template rwop(alias F) {
 	void op() { write(F(42)); }
      }

      ubyte asl(ubyte b) { return b << 1; }

      mixin rwop!(asl) rwAsl;

      void run() {
 	rwAsl.op();
      }
 }
 ---------------------
 class NotOk {
      void write(int v) { }

      template rwop(alias F) {
 	void op() { write(F(42)); }
      }

      ubyte asl(ubyte b) { return b << 1; }

      void run() {
 	// this works...
 	void rwAslOp() { write(asl(42)); }
 	rwAslOp();

 	// ... but this does not
 	mixin rwop!(asl) rwAsl;
 	rwAsl.op();
      }
 }
 --------------------

Added to DStress as http://dstress.kuehne.cn/run/m/mixin_13_A.d http://dstress.kuehne.cn/run/m/mixin_13_B.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFChcEt3w+/yD4P9tIRAm8mAKDLrolrXx/lrjHcYcFIKbAgXIiKqgCfZHKW BbuIJ27ckwmEcVppmEdWF3o= =wtSg -----END PGP SIGNATURE-----
May 14 2005