Skip to content

Commit

Permalink
Fix Issue 19284 - alias this not used in nested functions of a method
Browse files Browse the repository at this point in the history
  • Loading branch information
RazvanN7 committed Oct 9, 2018
1 parent 0a2b61c commit d8de5fd
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -2357,7 +2357,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
if (ad && ad.aliasthis)
{
Expression e;
e = new IdentifierExp(exp.loc, Id.This);
e = new ThisExp(exp.loc);
e = new DotIdExp(exp.loc, e, ad.aliasthis.ident);
e = new DotIdExp(exp.loc, e, exp.ident);
e = e.trySemantic(sc);
Expand Down
69 changes: 69 additions & 0 deletions test/runnable/aliasthis.d
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,74 @@ struct S15292

/***************************************************/

struct S19284a { int x; }
struct S19284b
{
S19284a s;
alias s this;
int t;
void f()
{
void wrapped()
{
x = 1;
t = 1;
}
wrapped(); // <-- 'x' not found, whereas 's.x' works fine
}

void f1()
{
x = 2;
}

void f2()
{
int x;
void wrapped()
{
x = 7;
}
wrapped();
assert(x == 7);
}

void f3()
{
void wrapped()
{
void wrapped2()
{
x = 5;
}
wrapped2();
}
wrapped();
}
}

void test19284()
{
S19284b t;

// nested function modifies alias this
t.f();
assert(t.x == 1);
assert(t.t == 1);

// member function modifies alias this
t.f1();
assert(t.x == 2);

// nested function does not modify alias this when it is shadowd by a local variable
t.f2();
assert(t.x == 2);

// multiple levels of nesting
t.f3();
assert(t.x == 5);
}

int main()
{
test1();
Expand Down Expand Up @@ -2028,6 +2096,7 @@ int main()
test13490();
test11355();
test14806();
test19284();

printf("Success\n");
return 0;
Expand Down

0 comments on commit d8de5fd

Please sign in to comment.