Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix Issue 9091 - Using __traits(getMember) on template argument fails…

… inside member function

Use ThisExp instead of VarExp to avoid interpretation on template arguments.
  • Loading branch information...
commit 8a781342c90c0fc93a52876ceb972500a1603d42 1 parent 9bf3352
@9rnsr 9rnsr authored
Showing with 53 additions and 7 deletions.
  1. +1 −1  src/mtype.c
  2. +52 −6 test/runnable/traits.d
View
2  src/mtype.c
@@ -8746,7 +8746,7 @@ Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident)
if (d->isFuncDeclaration())
{
// This is almost same as getRightThis() in expression.c
- Expression *e1 = new VarExp(e->loc, fdthis->vthis);
+ Expression *e1 = new ThisExp(e->loc);
e1 = e1->semantic(sc);
L2:
Type *t = e1->type->toBasetype();
View
58 test/runnable/traits.d
@@ -921,19 +921,64 @@ template isVariable9091(X...) if (X.length == 1)
}
class C9091
{
- void func()
+ int x; // some class members
+ void func(int n){ this.x = n; }
+
+ void test()
{
- enum is_x = isVariable9091!(__traits(getMember, C9091, "x"));
+ alias T = C9091;
+ enum is_x = isVariable9091!(__traits(getMember, T, "x"));
+
+ foreach (i, m; __traits(allMembers, T))
+ {
+ enum x = isVariable9091!(__traits(getMember, T, m));
+ static if (i == 0) // x
+ {
+ __traits(getMember, T, m) = 10;
+ assert(this.x == 10);
+ }
+ static if (i == 1) // func
+ {
+ __traits(getMember, T, m)(20);
+ assert(this.x == 20);
+ }
+ }
}
- int x; // some class members
}
struct S9091
{
- void func()
+ int x; // some struct members
+ void func(int n){ this.x = n; }
+
+ void test()
{
- enum is_x = isVariable9091!(__traits(getMember, S9091, "x"));
+ alias T = S9091;
+ enum is_x = isVariable9091!(__traits(getMember, T, "x"));
+
+ foreach (i, m; __traits(allMembers, T))
+ {
+ enum x = isVariable9091!(__traits(getMember, T, m));
+ static if (i == 0) // x
+ {
+ __traits(getMember, T, m) = 10;
+ assert(this.x == 10);
+ }
+ static if (i == 1) // func
+ {
+ __traits(getMember, T, m)(20);
+ assert(this.x == 20);
+ }
+ }
}
- int x; // some struct members
+}
+
+void test9091()
+{
+ auto c = new C9091();
+ c.test();
+
+ auto s = S9091();
+ s.test();
}
/********************************************************/
@@ -1072,6 +1117,7 @@ int main()
test1369();
test7608();
test7858();
+ test9091();
test5978();
test7408();
test9552();
Please sign in to comment.
Something went wrong with that request. Please try again.