www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is this a bug when creating proxies in classes?

reply "Gary Willoughby" <dev nomad.so> writes:
Compiling the following code:

	import std.typecons;

	class Foo
	{
		private int foo;

		mixin Proxy!(foo);

		this(int x)
		{
			this.foo = x;
		}
	}

	void main()
	{
	}

Produces this error:

:!rdmd --force -de -debug -w test.d
/usr/include/dmd/phobos/std/typecons.d(4043): Error: template 
instance isArray!(typeof(a)) template 'isArray' is not defined
test.d(7): Error: mixin test.Foo.Proxy!(foo) error instantiating
Failed: ["dmd", "-de", "-debug", "-w", "-v", "-o-", "test.d", 
"-I."]

Can anyone else confirm or am i doing something wrong. I'm using 
DMD 2.066.0 64bit Ubuntu 14.04.
Aug 25 2014
next sibling parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 08/25/2014 11:10 AM, Gary Willoughby wrote:
 Compiling the following code:

      import std.typecons;

      class Foo
      {
          private int foo;

          mixin Proxy!(foo);

          this(int x)
          {
              this.foo = x;
          }
      }

      void main()
      {
      }

 Produces this error:

 :!rdmd --force -de -debug -w test.d
 /usr/include/dmd/phobos/std/typecons.d(4043): Error: template instance
 isArray!(typeof(a)) template 'isArray' is not defined
 test.d(7): Error: mixin test.Foo.Proxy!(foo) error instantiating
 Failed: ["dmd", "-de", "-debug", "-w", "-v", "-o-", "test.d", "-I."]

 Can anyone else confirm or am i doing something wrong. I'm using DMD
 2.066.0 64bit Ubuntu 14.04.
isArray is defined in std.traits. I don't know why it doesn't work even though std.typecons does import it. The workaround is to import it yourself in your program: import std.traits; Ali
Aug 25 2014
prev sibling next sibling parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Monday, 25 August 2014 at 18:10:33 UTC, Gary Willoughby wrote:
 :!rdmd --force -de -debug -w test.d
 /usr/include/dmd/phobos/std/typecons.d(4043): Error: template 
 instance isArray!(typeof(a)) template 'isArray' is not defined
 test.d(7): Error: mixin test.Foo.Proxy!(foo) error instantiating
 Failed: ["dmd", "-de", "-debug", "-w", "-v", "-o-", "test.d", 
 "-I."]

 Can anyone else confirm or am i doing something wrong. I'm 
 using DMD 2.066.0 64bit Ubuntu 14.04.
It stopped working after this PR was merged: https://github.com/D-Programming-Language/phobos/pull/1899 But I suspect that something else is going on. The PR only introduced the call to `isArray` into `std.typecons.Proxy`.
Aug 25 2014
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 08/25/2014 11:38 AM, "Marc Schütz" <schuetzm gmx.net>" wrote:

 On Monday, 25 August 2014 at 18:10:33 UTC, Gary Willoughby wrote:
 :!rdmd --force -de -debug -w test.d
 /usr/include/dmd/phobos/std/typecons.d(4043): Error: template instance
 isArray!(typeof(a)) template 'isArray' is not defined
 test.d(7): Error: mixin test.Foo.Proxy!(foo) error instantiating
 Failed: ["dmd", "-de", "-debug", "-w", "-v", "-o-", "test.d", "-I."]

 Can anyone else confirm or am i doing something wrong. I'm using DMD
 2.066.0 64bit Ubuntu 14.04.
It stopped working after this PR was merged: https://github.com/D-Programming-Language/phobos/pull/1899 But I suspect that something else is going on. The PR only introduced the call to `isArray` into `std.typecons.Proxy`.
It can be explained if the mixed-in template is evaluated at the mixin context without bringing in the imported modules to that context. I don't know whether it is true or whether it is a known limitation. Ali
Aug 25 2014
parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Monday, 25 August 2014 at 18:44:36 UTC, Ali Çehreli wrote:
 It can be explained if the mixed-in template is evaluated at 
 the mixin context without bringing in the imported modules to 
 that context. I don't know whether it is true or whether it is 
 a known limitation.
You're right, that's it! It works when I import std.traits first. So... the fix is to import std.traits inside template Proxy. Going to submit a PR.
Aug 25 2014
parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Monday, 25 August 2014 at 19:12:48 UTC, Marc Schütz wrote:
 On Monday, 25 August 2014 at 18:44:36 UTC, Ali Çehreli wrote:
 It can be explained if the mixed-in template is evaluated at 
 the mixin context without bringing in the imported modules to 
 that context. I don't know whether it is true or whether it is 
 a known limitation.
You're right, that's it! It works when I import std.traits first. So... the fix is to import std.traits inside template Proxy. Going to submit a PR.
https://github.com/D-Programming-Language/phobos/pull/2463
Aug 25 2014
next sibling parent "Gary Willoughby" <dev nomad.so> writes:
On Monday, 25 August 2014 at 19:17:22 UTC, Marc Schütz wrote:
 On Monday, 25 August 2014 at 19:12:48 UTC, Marc Schütz wrote:
 On Monday, 25 August 2014 at 18:44:36 UTC, Ali Çehreli wrote:
 It can be explained if the mixed-in template is evaluated at 
 the mixin context without bringing in the imported modules to 
 that context. I don't know whether it is true or whether it 
 is a known limitation.
You're right, that's it! It works when I import std.traits first. So... the fix is to import std.traits inside template Proxy. Going to submit a PR.
https://github.com/D-Programming-Language/phobos/pull/2463
Smashing, ta.
Aug 25 2014
prev sibling parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 08/25/2014 12:17 PM, "Marc Schütz" <schuetzm gmx.net>" wrote:
 On Monday, 25 August 2014 at 19:12:48 UTC, Marc Schütz wrote:
 On Monday, 25 August 2014 at 18:44:36 UTC, Ali Çehreli wrote:
 It can be explained if the mixed-in template is evaluated at the
 mixin context without bringing in the imported modules to that
 context. I don't know whether it is true or whether it is a known
 limitation.
You're right, that's it! It works when I import std.traits first. So... the fix is to import std.traits inside template Proxy. Going to submit a PR.
https://github.com/D-Programming-Language/phobos/pull/2463
Thanks! And I learned from you in the pull request the following fact: <quote> Quoting http://dlang.org/template-mixin : "Unlike a template instantiation, a template mixin's body is evaluated within the scope where the mixin appears, not where the template declaration is defined. It is analogous to cutting and pasting the body of the template into the location of the mixin." </quote> Ali
Aug 25 2014
parent reply "Gary Willoughby" <dev nomad.so> writes:
On Monday, 25 August 2014 at 21:14:42 UTC, Ali Çehreli wrote:
 On 08/25/2014 12:17 PM, "Marc Schütz" <schuetzm gmx.net>" wrote:
 On Monday, 25 August 2014 at 19:12:48 UTC, Marc Schütz wrote:
 On Monday, 25 August 2014 at 18:44:36 UTC, Ali Çehreli wrote:
 It can be explained if the mixed-in template is evaluated at 
 the
 mixin context without bringing in the imported modules to 
 that
 context. I don't know whether it is true or whether it is a 
 known
 limitation.
You're right, that's it! It works when I import std.traits first. So... the fix is to import std.traits inside template Proxy. Going to submit a PR.
https://github.com/D-Programming-Language/phobos/pull/2463
Thanks! And I learned from you in the pull request the following fact: <quote> Quoting http://dlang.org/template-mixin : "Unlike a template instantiation, a template mixin's body is evaluated within the scope where the mixin appears, not where the template declaration is defined. It is analogous to cutting and pasting the body of the template into the location of the mixin." </quote> Ali
With that in mind what is strange is that if in my example you change the class for a struct everything works as expected. Why is that?
Aug 26 2014
next sibling parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Tuesday, 26 August 2014 at 18:13:52 UTC, Gary Willoughby wrote:
 With that in mind what is strange is that if in my example you 
 change the class for a struct everything works as expected. Why 
 is that?
This is bizarre... I tried a few things, but I have no idea. At first I thought the `static if` that calls `isArray` is inside another `static if`, but this is not the case. Might be a compiler bug?
Aug 26 2014
parent "Gary Willoughby" <dev nomad.so> writes:
On Tuesday, 26 August 2014 at 20:41:47 UTC, Marc Schütz wrote:
 On Tuesday, 26 August 2014 at 18:13:52 UTC, Gary Willoughby 
 wrote:
 With that in mind what is strange is that if in my example you 
 change the class for a struct everything works as expected. 
 Why is that?
This is bizarre... I tried a few things, but I have no idea. At first I thought the `static if` that calls `isArray` is inside another `static if`, but this is not the case. Might be a compiler bug?
Anyone else know or can reduce this if it's a bug?
Aug 28 2014
prev sibling parent reply "anonymous" <anonymous example.com> writes:
On Tuesday, 26 August 2014 at 18:13:52 UTC, Gary Willoughby wrote:
 With that in mind what is strange is that if in my example you 
 change the class for a struct everything works as expected. Why 
 is that?
That's because when not mixed into a class, Proxy did import std.traits: static if (!is(typeof(this) == class)) { private import std.traits;
Aug 28 2014
parent "Gary Willoughby" <dev nomad.so> writes:
On Thursday, 28 August 2014 at 16:23:48 UTC, anonymous wrote:
 On Tuesday, 26 August 2014 at 18:13:52 UTC, Gary Willoughby 
 wrote:
 With that in mind what is strange is that if in my example you 
 change the class for a struct everything works as expected. 
 Why is that?
That's because when not mixed into a class, Proxy did import std.traits: static if (!is(typeof(this) == class)) { private import std.traits;
Ah right, yes. ta.
Aug 28 2014
prev sibling parent "Martin Nowak" <code dawg.eu> writes:
On Monday, 25 August 2014 at 18:10:33 UTC, Gary Willoughby wrote:
 	class Foo
 	{
 		private int foo;

 		mixin Proxy!(foo);

 		this(int x)
 		{
 			this.foo = x;
 		}
 	}
Apparently Proxy doesn't work correctly inside classes. Is wrapping something inside a class particularly useful? Please comment on https://issues.dlang.org/show_bug.cgi?id=13623.
Oct 16 2014