Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue 19284 - alias this not used in nested functions of a method #8814

Merged
merged 1 commit into from Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dmd/expressionsem.d
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
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