January 20, 2009
Reply to Trass3r,

> auto members = __traits(allMembers, typeof(this));

try switching that to 

> const[][] members = __traits(allMembers, typeof(this));

if that doesn't fix it try dropping this part (it might make it clearer what's going on)

> static if (is (typeof(__traits(getMember, this, members[m])) F ==
> function))
> {
> pragma(msg, "function");
> }

Looking at the rest of the thread, I think you might be looking at a bug.


January 20, 2009
Reply to Trass3r,

> Sergey Gromov schrieb:
> 
>> auto members = __traits(allMembers, Cls);
>
> Seeing this really simple example crashing makes me think that this
> has to be a bug.
> 

that auto might be mucking it up (if so it would be a bug).


January 20, 2009
Tue, 20 Jan 2009 21:12:18 +0000 (UTC), BCS wrote:

> Reply to Trass3r,
> 
>> Sergey Gromov schrieb:
>> 
>>> auto members = __traits(allMembers, Cls);
>>
>> Seeing this really simple example crashing makes me think that this has to be a bug.
>> 
> 
> that auto might be mucking it up (if so it would be a bug).

Bingo. Replacing it with

  string[] members = __traits(allMembers, Cls);

makes it compile.  Therefore

class Cls
{
  int bar;
  char[] baz;
}
string foo()
{
  string[] members = __traits(allMembers, Cls);
  string result;
  foreach(m; members)
    result ~= m ~ " ";
  return result;
}
pragma(msg, foo());

works.
January 20, 2009
This works:

template classMixin()
{
static this()
{
	const string[] members = __traits(allMembers, typeof(this));
	pragma(msg, foo(members));
}
}

string foo(const string[] members)
{
	string result;
	foreach(m; members)
		result ~= m ~ " ";
	return result;
}


But there must exist a better solution to this.
January 20, 2009
Trass3r schrieb:
> This works:
> 
> string foo(const string[] members)
> {
>     string result;
>     foreach(m; members)
>         result ~= m ~ " ";
>     return result;
> }
> 

Furthermore there seems to be no way to use these member names in a __traits(getMember, class, m) call.

This is driving me crazy.
January 20, 2009
On Wed, Jan 21, 2009 at 8:25 AM, Trass3r <mrmocool@gmx.de> wrote:
> Trass3r schrieb:
>>
>> This works:
>>
>> string foo(const string[] members)
>> {
>>    string result;
>>    foreach(m; members)
>>        result ~= m ~ " ";
>>    return result;
>> }
>>
>
> Furthermore there seems to be no way to use these member names in a __traits(getMember, class, m) call.
>
> This is driving me crazy.

Well, it does start with two underscores.  That may be trying to tell you something. :-)

If you find a real bug definitely report it.   Also note that your bug reports will be treated much more seriously if you can provide a compelling use case which is difficult or impossible to work around short of fixing the bug.  "If you fix this then I will be able create cool thing X" seems to increase your chances of getting a fix significantly.

--bb
January 21, 2009
Sergey Gromov wrote:
> Comment out the traits and it compiles.  Traits are supposed to be
> compile-time.  How's that possible for them to prevent compile-time
> evaluation?

It's the amazing powers of the DMD CTFE engine! And it's why I don't use d2 these days.

I think I'll dust off some old code I have that worked with dmd 2.009 (and failed with 2.010 and 2.011) and try making it work. I don't think the bugs that I filed in reference to that code ever got fixed, though.
1 2
Next ›   Last »