On 3/17/2014 7:07 AM, Etienne Cimon wrote:

I don't see this on the vibe.d master branch, it looks more like this now:

You are right, I am not on the master branch. I just wanted to do a
quick test; no need for the latest code. Or so I thought.

I have version v0.7.18, acquired via dub. I suppose I can change the
dependency to ~master in the dub.json

(side note, isn't it not supposed to be called package.json, that is
what the website says? for some reason I ended up with dub.json's)

enum fname = getAttribute!(T, mname, NameAttribute)(NameAttribute(underscoreStrip(mname))).name;

and

private static T getAttribute(TT, string mname, T)(T default_value)
{
	enum val = findFirstUDA!(T, __traits(getMember, TT, mname));
	static if (val.found) return val.value;
	else return default_value;
}

Which leads me to believe that the cause of this error is because D expects this to be defined when passing a class / struct member alias instead of the type / member name as a template parameter. It could be a compiler bug... but I'm not so sure why the vibe.d master would trigger this sort of error, because I couldn't find your reproduction in the master branch. Did you use an older version?

From the dlang website:

import std.stdio;

struct S {
int mx;
static int my;
}

void main() {
S s;

traits(getMember, s, "mx") = 1; // same as s.mx=1;
writeln(
traits(getMember, s, "m" ~ "x")); // 1

traits(getMember, S, "mx") = 1; // error, no this for S.mx <<---
traits(getMember, S, "my") = 2; // ok
}

What is being returned by __traits(getMember...) is an expression.
So, in my test snippet I basically did:

struct S
{

int mx;
static int my;

}

void main()
{

S s;
pragma(msg, __traits(getMember, S, "mx"));

}

Which, for reasons obvious to me now, is like calling a member variable
without a instance, therefor the error "need 'this' for ..."