Skip to content

Commit

Permalink
fix Issue 11800 - alias this matching incorrectly changes lvalue-ness
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Dec 22, 2013
1 parent 6854a58 commit d1fec04
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/cast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1078,20 +1078,21 @@ Expression *Expression::castTo(Scope *sc, Type *t)
else
{
if (typeb->ty == Tstruct)
{ TypeStruct *ts = (TypeStruct *)typeb;
{
TypeStruct *ts = (TypeStruct *)typeb;
if (!(tb->ty == Tstruct && ts->sym == ((TypeStruct *)tb)->sym) &&
ts->sym->aliasthis)
{ /* Forward the cast to our alias this member, rewrite to:
{
/* Forward the cast to our alias this member, rewrite to:
* cast(to)e1.aliasthis
*/
Expression *e1 = resolveAliasThis(sc, this);
Expression *e2 = new CastExp(loc, e1, tb);
e2 = e2->semantic(sc);
return e2;
Expression *ex = resolveAliasThis(sc, this);
return ex->castTo(sc, t);
}
}
else if (typeb->ty == Tclass)
{ TypeClass *ts = (TypeClass *)typeb;
{
TypeClass *ts = (TypeClass *)typeb;
if (ts->sym->aliasthis)
{
if (tb->ty == Tclass)
Expand Down
28 changes: 28 additions & 0 deletions test/runnable/aliasthis.d
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,33 @@ void test11261()
}
}

/***************************************************/
// 11800

struct A11800
{
B11800 b;
alias b this;
}

struct B11800
{
static struct Value {}
Value value;
alias value this;

void foo(ref const B11800 rhs)
{
}
}

void test11800()
{
A11800 a;
B11800 b;
b.foo(a);
}

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

int main()
Expand Down Expand Up @@ -1600,6 +1627,7 @@ int main()
test10004();
test10180();
test10456();
test11800();

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

0 comments on commit d1fec04

Please sign in to comment.